int main() { arena = Arena_new(); start_socket_server(); start_socket_client(); test_unconnected_put(); //fatal, reconnect start_socket_client(); test_con(); test_con_2(); //fatal, reconnect start_socket_client(); test_con(); test_put(); test_read(); test_take(); test_upt(); //fatal, reconnect start_socket_client(); test_con(); test_upl(); stop_socket_server(); return 0; }
int main() { init_library(); start_socket_server(); return 0; }
void test_open_socket_fork(void) { /* This subtest will start a server and client using TCP. The client will * open the socket with SOCK_CLOEXEC turned off, so that after a fork+exec, the * socket should stay valid. * o * / | * server | * (accept) | * | | \ * | | client * | | (connect) * | | | \ * | | | client_fork * | | | (exec t67a) * (read) | | (write) * | | | / * | | (waitpid client_fork) * \ | | * (waitpid server) | * | / * (waitpid client) * | * o */ pid_t pid_server, pid_client; int result; pid_server = fork(); if (pid_server < 0) e(1); if (pid_server == 0) { start_socket_server(FORK_PORT); return; /* Never reached */ } pid_client = fork(); if (pid_client < 0) e(2); if (pid_client == 0) { pid_t pid_client_fork; int sockfd; sockfd = start_socket_client(FORK_PORT, 0); if (sockfd < 0) e(4); pid_client_fork = fork(); if (pid_client_fork < 0) { e(5); exit(5); } if (pid_client_fork == 0) { /* We're a fork of the client. After we exec, the * socket should stay valid due to lack of SOCK_CLOEXEC * flag. */ char sockfd_buf[2]; int flags; /* Verify O_CLOEXEC is off */ flags = fcntl(sockfd, F_GETFD); if (flags < 0) e(5); if (flags & FD_CLOEXEC) e(6); /* t67a will verify that it can't write to sockfd and * that opening a new file will yield a file descriptor * with a higher number. */ snprintf(sockfd_buf, sizeof(sockfd_buf), "%d", sockfd); execl("./t67a", "t67a", sockfd_buf, NULL); /* Should not reach this */ exit(1); } else { if (waitpid(pid_client_fork, &result, 0) < 0) e(8); exit(WEXITSTATUS(result)); /* Pass on error to main */ } exit(0); /* Never reached */ } if (waitpid(pid_server, &result, 0) < 0) e(3); if (waitpid(pid_client, &result, 0) < 0) e(4); /* Let's inspect client result */ if (WEXITSTATUS(result) != 0) e(5); }
int main (int argc, char *argv[]) { int ch; bool no_signals = false; bool test_config = false; bool export_config = false; bool export_config_schema = false; pthread_t thid; char *uid = NULL; char *gid = NULL; start_heap = sbrk(0); setlocale(LC_ALL, ""); bindtextdomain("bareos", LOCALEDIR); textdomain("bareos"); init_stack_dump(); my_name_is(argc, argv, "bareos-sd"); init_msg(NULL, NULL); daemon_start_time = time(NULL); /* * Sanity checks */ if (TAPE_BSIZE % B_DEV_BSIZE != 0 || TAPE_BSIZE / B_DEV_BSIZE == 0) { Emsg2(M_ABORT, 0, _("Tape block size (%d) not multiple of system size (%d)\n"), TAPE_BSIZE, B_DEV_BSIZE); } if (TAPE_BSIZE != (1 << (ffs(TAPE_BSIZE)-1))) { Emsg1(M_ABORT, 0, _("Tape block size (%d) is not a power of 2\n"), TAPE_BSIZE); } while ((ch = getopt(argc, argv, "c:d:fg:mpstu:vx:?")) != -1) { switch (ch) { case 'c': /* configuration file */ if (configfile != NULL) { free(configfile); } configfile = bstrdup(optarg); break; case 'd': /* debug level */ if (*optarg == 't') { dbg_timestamp = true; } else { debug_level = atoi(optarg); if (debug_level <= 0) { debug_level = 1; } } break; case 'f': /* run in foreground */ foreground = true; break; case 'g': /* set group id */ gid = optarg; break; case 'm': /* print kaboom output */ prt_kaboom = true; break; case 'p': /* proceed in spite of I/O errors */ forge_on = true; break; case 's': /* no signals */ no_signals = true; break; case 't': test_config = true; break; case 'u': /* set uid */ uid = optarg; break; case 'v': /* verbose */ verbose++; break; case 'x': /* export configuration/schema and exit */ if (*optarg == 's') { export_config_schema = true; } else if (*optarg == 'c') { export_config = true; } else { usage(); } break; case '?': default: usage(); break; } } argc -= optind; argv += optind; if (argc) { if (configfile != NULL) { free(configfile); } configfile = bstrdup(*argv); argc--; argv++; } if (argc) { usage(); } /* * See if we want to drop privs. */ if (geteuid() == 0) { drop(uid, gid, false); } if (!no_signals) { init_signals(terminate_stored); } if (export_config_schema) { POOL_MEM buffer; my_config = new_config_parser(); init_sd_config(my_config, configfile, M_ERROR_TERM); print_config_schema_json(buffer); printf("%s\n", buffer.c_str()); goto bail_out; } my_config = new_config_parser(); parse_sd_config(my_config, configfile, M_ERROR_TERM); if (export_config) { my_config->dump_resources(prtmsg, NULL); goto bail_out; } if (!foreground && !test_config) { daemon_start(); /* become daemon */ init_stack_dump(); /* pick up new pid */ } if (init_crypto() != 0) { Jmsg((JCR *)NULL, M_ERROR_TERM, 0, _("Cryptography library initialization failed.\n")); } if (!check_resources()) { Jmsg((JCR *)NULL, M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), my_config->get_base_config_path()); } init_reservations_lock(); if (test_config) { terminate_stored(0); } my_name_is(0, (char **)NULL, me->name()); /* Set our real name */ create_pid_file(me->pid_directory, "bareos-sd", get_first_port_host_order(me->SDaddrs)); read_state_file(me->working_directory, "bareos-sd", get_first_port_host_order(me->SDaddrs)); read_crypto_cache(me->working_directory, "bareos-sd", get_first_port_host_order(me->SDaddrs)); set_jcr_in_tsd(INVALID_JCR); /* * Make sure on Solaris we can run concurrent, watch dog + servers + misc */ set_thread_concurrency(me->MaxConcurrentJobs * 2 + 4); lmgr_init_thread(); /* initialize the lockmanager stack */ load_sd_plugins(me->plugin_directory, me->plugin_names); cleanup_old_files(); /* Ensure that Volume Session Time and Id are both * set and are both non-zero. */ VolSessionTime = (uint32_t)daemon_start_time; if (VolSessionTime == 0) { /* paranoid */ Jmsg0(NULL, M_ABORT, 0, _("Volume Session Time is ZERO!\n")); } /* * Start the device allocation thread */ create_volume_lists(); /* do before device_init */ if (pthread_create(&thid, NULL, device_initialization, NULL) != 0) { berrno be; Emsg1(M_ABORT, 0, _("Unable to create thread. ERR=%s\n"), be.bstrerror()); } start_watchdog(); /* start watchdog thread */ if (me->jcr_watchdog_time) { init_jcr_subsystem(me->jcr_watchdog_time); /* start JCR watchdogs etc. */ } start_statistics_thread(); #if HAVE_NDMP /* * Seperate thread that handles NDMP connections */ if (me->ndmp_enable) { start_ndmp_thread_server(me->NDMPaddrs, me->MaxConnections); } #endif /* * Single server used for Director/Storage and File daemon */ start_socket_server(me->SDaddrs); /* to keep compiler quiet */ terminate_stored(0); bail_out: return 0; }