int main(int argc, char **argv) { #ifndef __MINGW32__ FILE *fileconf; #endif char *tmp; char lichdir[256] = { '\0' }; char datadir[512] = { '\0' }; int nerr; sig_setup(); #ifndef __MINGW32__ snprintf(lichdir, 256, "%s%s", getenv("HOME"), "/.lich.cfg"); fileconf = fopen(lichdir, "rb"); if (!fileconf) { perror("fopen"); fprintf(stderr, "Your `$HOME/.lich.cfg' file cannot be opened: please create the file and put the full directory name Lich should use for settings/config files in it.\n\nFor example, to do that, you could type: echo \"$HOME/lich\" > $HOME/.lich.cfg\n"); exit(EXIT_FAILURE); } fgets(lichdir, 256, fileconf); fclose(fileconf); lichdir[strnlen(lichdir, 256) - 1] = '/'; chdir(lichdir); #else NtInitialize(&argc, &argv); strncpy(lichdir, argv[0], 255); tmp = &lichdir[strlen(lichdir)]; while (tmp && (*tmp != '\\') && (*tmp != '/')) { tmp--; } *tmp = '\0'; chdir(lichdir); #endif init_ruby_interpreter(argc, argv); init_libs(); prep_ruby_env(); getcwd(lichdir, 255); lichdir[strlen(lichdir) + 1] = '\0'; lichdir[strlen(lichdir)] = RSTRING(rb_const_get(rb_cFile, rb_intern("SEPARATOR")))->ptr[0]; strcpy(datadir, lichdir); strcat(datadir, "data"); datadir[strlen(datadir)] = lichdir[strlen(lichdir) - 1]; rb_gv_set("$data_dir", rb_str_new(datadir, strlen(datadir))); rb_gv_set("$lich_dir", rb_str_new(lichdir, strlen(lichdir))); ruby_safe_level = 0; if (nerr = ruby_exec()) { tmp = RSTRING(rb_funcall(rb_gv_get("$!"), rb_intern("to_s"), 0))->ptr; if (!strncasecmp(tmp, "exit", 4)) ruby_stop(0); fprintf(stderr, "%s\n", tmp); fprintf(stderr, "%s\n", RSTRING(rb_funcall(rb_funcall(rb_gv_get("$!"), rb_intern("backtrace"), 0), rb_intern("join"), 1, rb_str_new2("\n")))->ptr); ruby_stop(nerr); } ruby_stop(0); }
/** * dr_init * @brief Initialization routine for drmgr and lsslot * */ inline int dr_init(void) { int rc; rc = dr_lock(); if (rc) { say(ERROR, "Unable to obtain Dynamic Reconfiguration lock. " "Please try command again later.\n"); return -1; } log_fd = open(DR_LOG_PATH, O_RDWR | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (log_fd == -1) { log_fd = 0; say(ERROR, "Could not open log file %s\n\t%s\n", DR_LOG_PATH, strerror(errno)); } else { time_t t; char tbuf[128]; /* Insert seperator at beginning of drmgr invocation */ time(&t); strftime(tbuf, 128, "%b %d %T %G", localtime(&t)); say(DEBUG, "\n########## %s ##########\n", tbuf); } /* Mask signals so we do not get interrupted */ if (sig_setup()) { say(ERROR, "Could not mask signals to avoid interrupts\n"); if (log_fd) close(log_fd); dr_unlock(); return -1; } rc = check_kmods(); if (rc) { if (log_fd) close(log_fd); dr_unlock(); } return rc; }
PUBLIC int main(int argc, char *argv[]) { jmp_buf jmpbuf; struct sigaction sa; struct name *to, *cc, *bcc, *smopts; #ifdef MIME_SUPPORT struct name *attach_optargs; struct name *attach_end; #endif char *subject; const char *ef; char nosrc = 0; const char *rc; int Hflag; int i; /* * For portability, call setprogname() early, before * getprogname() is called. */ (void)setprogname(argv[0]); /* * Set up a reasonable environment. * Figure out whether we are being run interactively, * start the SIGCHLD catcher, and so forth. * (Other signals are setup later by sig_setup().) */ (void)sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART; sa.sa_handler = sigchild; (void)sigaction(SIGCHLD, &sa, NULL); if (isatty(0)) assign(ENAME_INTERACTIVE, ""); image = -1; /* * Now, determine how we are being used. * We successively pick off - flags. * If there is anything left, it is the base of the list * of users to mail to. Argp will be set to point to the * first of these users. */ rc = NULL; ef = NULL; to = NULL; cc = NULL; bcc = NULL; smopts = NULL; subject = NULL; Hflag = 0; #ifdef MIME_SUPPORT attach_optargs = NULL; attach_end = NULL; while ((i = getopt(argc, argv, ":~EH:INT:a:b:c:dfinr:s:u:v")) != -1) #else while ((i = getopt(argc, argv, ":~EH:INT:b:c:dfinr:s:u:v")) != -1) #endif { switch (i) { case 'T': /* * Next argument is temp file to write which * articles have been read/deleted for netnews. */ Tflag = optarg; if ((i = creat(Tflag, 0600)) < 0) { warn("%s", Tflag); exit(1); } (void)close(i); break; #ifdef MIME_SUPPORT case 'a': { struct name *np; np = nalloc(optarg, 0); if (attach_end == NULL) attach_optargs = np; else { np->n_blink = attach_end; attach_end->n_flink = np; } attach_end = np; break; } #endif case 'u': /* * Next argument is person to pretend to be. */ myname = optarg; (void)unsetenv("MAIL"); break; case 'i': /* * User wants to ignore interrupts. * Set the variable "ignore" */ assign(ENAME_IGNORE, ""); break; case 'd': debug++; break; case 'r': rc = optarg; break; case 's': /* * Give a subject field for sending from * non terminal */ subject = optarg; break; case 'f': /* * User is specifying file to "edit" with Mail, * as opposed to reading system mailbox. * If no argument is given after -f, we read his * mbox file. * * getopt() can't handle optional arguments, so here * is an ugly hack to get around it. */ if ((argv[optind]) && (argv[optind][0] != '-')) ef = argv[optind++]; else ef = "&"; break; case 'H': /* * Print out the headers and quit. */ Hflag = get_Hflag(argv); break; case 'n': /* * User doesn't want to source /usr/lib/Mail.rc */ nosrc++; break; case 'N': /* * Avoid initial header printing. */ assign(ENAME_NOHEADER, ""); break; case 'v': /* * Send mailer verbose flag */ assign(ENAME_VERBOSE, ""); break; case 'I': case '~': /* * We're interactive */ assign(ENAME_INTERACTIVE, ""); break; case 'c': /* * Get Carbon Copy Recipient list */ cc = cat(cc, lexpand(optarg, GCC)); break; case 'b': /* * Get Blind Carbon Copy Recipient list */ bcc = cat(bcc, lexpand(optarg, GBCC)); break; case 'E': /* * Don't send empty files. */ assign(ENAME_DONTSENDEMPTY, ""); break; case ':': /* * An optarg was expected but not found. */ if (optopt == 'H') { Hflag = get_Hflag(NULL); break; } (void)fprintf(stderr, "%s: option requires an argument -- %c\n", getprogname(), optopt); /* FALLTHROUGH */ case '?': /* * An unknown option flag. We need to do the * error message. */ if (optopt != '?') (void)fprintf(stderr, "%s: unknown option -- %c\n", getprogname(), optopt); usage(); /* print usage message and die */ /*NOTREACHED*/ } } for (i = optind; (argv[i]) && (*argv[i] != '-'); i++) to = cat(to, nalloc(argv[i], GTO)); for (/*EMPTY*/; argv[i]; i++) smopts = cat(smopts, nalloc(argv[i], GSMOPTS)); /* * Check for inconsistent arguments. */ if (to == NULL && (subject != NULL || cc != NULL || bcc != NULL)) errx(EXIT_FAILURE, "You must specify direct recipients with -s, -c, or -b."); if (ef != NULL && to != NULL) { errx(EXIT_FAILURE, "Cannot give -f and people to send to."); } if (Hflag != 0 && to != NULL) errx(EXIT_FAILURE, "Cannot give -H and people to send to."); #ifdef MIME_SUPPORT if (attach_optargs != NULL && to == NULL) errx(EXIT_FAILURE, "Cannot give -a without people to send to."); #endif tinit(); /* must be done before loading the rcfile */ input = stdin; mailmode = Hflag ? mm_hdrsonly : to ? mm_sending : mm_receiving; spreserve(); if (!nosrc) load(_PATH_MASTER_RC); /* * Expand returns a savestr, but load only uses the file name * for fopen, so it's safe to do this. */ if (rc == NULL && (rc = getenv("MAILRC")) == NULL) rc = "~/.mailrc"; load(expand(rc)); setscreensize(); /* do this after loading the rcfile */ #ifdef USE_EDITLINE /* * This is after loading the MAILRC so we can use value(). * Avoid editline in mm_hdrsonly mode or pipelines will screw * up. XXX - there must be a better way! */ if (mailmode != mm_hdrsonly) init_editline(); #endif sig_setup(); switch (mailmode) { case mm_sending: (void)mail(to, cc, bcc, smopts, subject, mime_attach_optargs(attach_optargs)); /* * why wait? */ exit(senderr); break; /* XXX - keep lint happy */ case mm_receiving: case mm_hdrsonly: /* * Ok, we are reading mail. * Decide whether we are editing a mailbox or reading * the system mailbox, and open up the right stuff. */ if (ef == NULL) ef = "%"; if (setfile(ef) < 0) exit(1); /* error already reported */ if (value(ENAME_QUIET) == NULL) (void)printf("Mail version %s. Type ? for help.\n", version); if (mailmode == mm_hdrsonly) show_headers_and_exit(Hflag); /* NORETURN */ announce(); (void)fflush(stdout); if (setjmp(jmpbuf) != 0) { /* Return here if quit() fails below. */ (void)printf("Use 'exit' to quit without saving changes.\n"); } commands(); /* Ignore these signals from now on! */ (void)signal(SIGHUP, SIG_IGN); (void)signal(SIGINT, SIG_IGN); (void)signal(SIGQUIT, SIG_IGN); quit(jmpbuf); break; default: assert(/*CONSTCOND*/0); break; } return 0; }
int main(int argc, char* argv[]) { char *path; char cmd[256]; int udev = 0; uev_t timer; /* Bootstrap timer, on timeout call finalize() */ uev_ctx_t loop; /* * finit/init/telinit client tool uses /dev/initctl pipe * for compatibility but initctl client tool uses socket */ if (getpid() != 1) return client(argc, argv); /* * Initalize event context. */ uev_init(&loop); ctx = &loop; /* * Set PATH and SHELL early to something sane */ setenv("PATH", _PATH_STDPATH, 1); setenv("SHELL", _PATH_BSHELL, 1); /* * Mount base file system, kernel is assumed to run devtmpfs for /dev */ chdir("/"); umask(0); mount("none", "/proc", "proc", 0, NULL); mount("none", "/sys", "sysfs", 0, NULL); if (fisdir("/proc/bus/usb")) mount("none", "/proc/bus/usb", "usbfs", 0, NULL); /* * Parse kernel command line (debug, rescue, splash, etc.) * Also calls log_init() to set correct log level */ conf_parse_cmdline(); /* Set up canvas */ if (!rescue && !log_is_debug()) screen_init(); /* * In case of emergency. */ emergency_shell(); /* * Initial setup of signals, ignore all until we're up. */ sig_init(); /* * Load plugins early, finit.conf may contain references to * features implemented by plugins. */ plugin_init(&loop); /* * Hello world. */ banner(); /* * Check file filesystems in /etc/fstab */ for (int pass = 1; pass < 10 && !rescue; pass++) { if (fsck(pass)) break; } /* * Initialize .conf system and load static /etc/finit.conf * Also initializes global_rlimit[] for udevd, below. */ conf_init(); /* * Some non-embedded systems without an initramfs may not have /dev mounted yet * If they do, check if system has udevadm and perform cleanup from initramfs */ if (!fismnt("/dev")) mount("udev", "/dev", "devtmpfs", MS_RELATIME, "size=10%,nr_inodes=61156,mode=755"); else if (whichp("udevadm")) run_interactive("udevadm info --cleanup-db", "Cleaning up udev db"); /* Some systems use /dev/pts */ makedir("/dev/pts", 0755); mount("devpts", "/dev/pts", "devpts", 0, "gid=5,mode=620"); /* * Some systems rely on us to both create /dev/shm and, to mount * a tmpfs there. Any system with dbus needs shared memory, so * mount it, unless its already mounted, but not if listed in * the /etc/fstab file already. */ makedir("/dev/shm", 0755); if (!fismnt("/dev/shm") && !ismnt("/etc/fstab", "/dev/shm")) mount("shm", "/dev/shm", "tmpfs", 0, NULL); /* * New tmpfs based /run for volatile runtime data * For details, see http://lwn.net/Articles/436012/ */ if (fisdir("/run") && !fismnt("/run")) mount("tmpfs", "/run", "tmpfs", MS_NODEV, "mode=0755,size=10%"); umask(022); /* Bootstrap conditions, needed for hooks */ cond_init(); /* * Populate /dev and prepare for runtime events from kernel. * Prefer udev if mdev is also available on the system. */ path = which("udevd"); if (!path) path = which("/lib/systemd/systemd-udevd"); if (path) { /* Desktop and server distros usually have a variant of udev */ udev = 1; /* Register udevd as a monitored service */ snprintf(cmd, sizeof(cmd), "[S12345789] pid:udevd %s -- Device event managing daemon", path); if (service_register(SVC_TYPE_SERVICE, cmd, global_rlimit, NULL)) { _pe("Failed registering %s", path); udev = 0; } else { snprintf(cmd, sizeof(cmd), ":1 [S] <svc%s> " "udevadm trigger -c add -t devices " "-- Requesting device events", path); service_register(SVC_TYPE_RUN, cmd, global_rlimit, NULL); snprintf(cmd, sizeof(cmd), ":2 [S] <svc%s> " "udevadm trigger -c add -t subsystems " "-- Requesting subsystem events", path); service_register(SVC_TYPE_RUN, cmd, global_rlimit, NULL); } free(path); } else { path = which("mdev"); if (path) { /* Embedded Linux systems usually have BusyBox mdev */ if (log_is_debug()) touch("/dev/mdev.log"); snprintf(cmd, sizeof(cmd), "%s -s", path); free(path); run_interactive(cmd, "Populating device tree"); } } /* * Start built-in watchdog as soon as possible, if enabled */ wdogpid = watchdog(argv[0]); /* * Mount filesystems */ if (!rescue) { #ifdef REMOUNT_ROOTFS run("mount -n -o remount,rw /"); #endif #ifdef SYSROOT mount(SYSROOT, "/", NULL, MS_MOVE, NULL); #endif } if (!rescue) { _d("Root FS up, calling hooks ..."); plugin_run_hooks(HOOK_ROOTFS_UP); umask(0); if (run_interactive("mount -na", "Mounting filesystems")) plugin_run_hooks(HOOK_MOUNT_ERROR); _d("Calling extra mount hook, after mount -a ..."); plugin_run_hooks(HOOK_MOUNT_POST); run("swapon -ea"); umask(0022); } /* Base FS up, enable standard SysV init signals */ sig_setup(&loop); if (!rescue) { _d("Base FS up, calling hooks ..."); plugin_run_hooks(HOOK_BASEFS_UP); } /* * Set up inotify watcher for /etc/finit.d and read all .conf * files to figure out how to bootstrap the system. */ conf_monitor(&loop); /* * Initalize state machine and start all bootstrap tasks * NOTE: no network available! */ sm_init(&sm); sm_step(&sm); /* Debian has this little script to copy generated rules while the system was read-only */ if (udev && fexist("/lib/udev/udev-finish")) run_interactive("/lib/udev/udev-finish", "Finalizing udev"); /* Start new initctl API responder */ api_init(&loop); umask(022); /* * Wait for all SVC_TYPE_RUNTASK to have completed their work in * [S], or timeout, before calling finalize() */ _d("Starting bootstrap finalize timer ..."); uev_timer_init(&loop, &timer, service_bootstrap_cb, finalize, 1000, 1000); /* * Enter main loop to monior /dev/initctl and services */ _d("Entering main loop ..."); return uev_run(&loop, 0); }
int main(int argc, char **argv) { try { if (argc < 2) { throw argc; } } catch (int) { usage(); exit(1); } char *s; Random_init(); arg_user_agent = new char[MAX_PF_LEN + 1](); // free'd at end param_check() //memmove(arg_user_agent, PEER_PFX, MAX_PF_LEN); strcpy(arg_user_agent, PEER_PFX); cfg_user_agent = new char[strlen(PACKAGE_NAME) + strlen(PACKAGE_VERSION) + 2](); if (!cfg_user_agent) return -1; sprintf(cfg_user_agent, "%s/%s", PACKAGE_NAME, PACKAGE_VERSION); do { s = strchr(cfg_user_agent, ' '); if (s != NULL) *s = '-'; } while (s); if (param_check(argc, argv) < 0) { if (arg_user_agent) delete[] arg_user_agent; return -1; } if (arg_flg_make_torrent) { if (!arg_announce) { CONSOLE.Warning(1, "Please use -u to specify an announce URL!"); return EXIT_FAILURE; } if (!arg_save_as) { CONSOLE.Warning(1, "Please use -s to specify a metainfo file name!"); return EXIT_FAILURE; } if (BTCONTENT.InitialFromFS(arg_metainfo_file, arg_announce, arg_piece_length) < 0 || BTCONTENT.CreateMetainfoFile(arg_save_as) < 0) { CONSOLE.Warning(1, "create metainfo failed."); return EXIT_FAILURE; } CONSOLE.Print("Create metainfo file %s successful.", arg_save_as); return EXIT_SUCCESS; } if (arg_daemon) CONSOLE.Daemonize(); if (!arg_flg_exam_only && (!arg_flg_check_only || arg_flg_force_seed_mode)) if (arg_ctcs) CTCS.Initial(); if (BTCONTENT.InitialFromMI(arg_metainfo_file, arg_save_as) < 0) { CONSOLE.Warning(1, "error, initial meta info failed."); exit(1); } if (!arg_flg_exam_only && (!arg_flg_check_only || arg_flg_force_seed_mode)) { if (WORLD.Initial_ListenPort() < 0) { CONSOLE.Warning(2, "warn, you can't accept connections."); } if (Tracker.Initial() < 0) { CONSOLE.Warning(1, "error, tracker setup failed."); return EXIT_FAILURE; } sig_setup(); // setup signal handling CONSOLE.Interact ("Press 'h' or '?' for help (display/control client options)."); Downloader(); if (cfg_cache_size) BTCONTENT.FlushCache(); } if (!arg_flg_exam_only) BTCONTENT.SaveBitfield(); WORLD.CloseAll(); if (arg_verbose) CONSOLE.cpu(); return EXIT_SUCCESS; }
int main(int argc, char* argv[]) { if (getpid() != 1) return client(argc, argv); /* * Hello world. */ banner(); /* * Initial setup of signals, ignore all until we're up. */ sig_init(); /* * Mount base file system, kernel is assumed to run devtmpfs for /dev */ chdir("/"); umask(0); mount("none", "/proc", "proc", 0, NULL); mount("none", "/proc/bus/usb", "usbfs", 0, NULL); mount("none", "/sys", "sysfs", 0, NULL); mkdir("/dev/pts", 0755); mkdir("/dev/shm", 0755); mount("none", "/dev/pts", "devpts", 0, "gid=5,mode=620"); mount("none", "/dev/shm", "tmpfs", 0, NULL); umask(022); /* * Parse kernel parameters */ parse_kernel_cmdline(); /* * Populate /dev and prepare for runtime events from kernel. */ run_interactive(SETUP_DEVFS, "Populating device tree"); /* * Parse configuration file */ parse_finit_conf(FINIT_CONF); /* * Load plugins. Must run after finit.conf has registered * all services, or service plugins won't have anything to * hook on to. */ print_desc("Loading plugins", NULL); print_result(plugin_load_all(PLUGIN_PATH)); /* * Mount filesystems */ #ifdef REMOUNT_ROOTFS_RW run("/bin/mount -n -o remount,rw /"); #endif #ifdef SYSROOT run(SYSROOT, "/", NULL, MS_MOVE, NULL); #endif _d("Root FS up, calling hooks ..."); plugin_run_hooks(HOOK_ROOTFS_UP); umask(0); run("/bin/mount -na"); run("/sbin/swapon -ea"); umask(0022); /* Cleanup stale files, if any still linger on. */ run_interactive("rm -rf /tmp/* /var/run/* /var/lock/*", "Cleanup temporary directories"); /* Base FS up, enable standard SysV init signals */ sig_setup(); _d("Base FS up, calling hooks ..."); plugin_run_hooks(HOOK_BASEFS_UP); /* * Start all bootstrap tasks, no network available! */ svc_bootstrap(); /* * Network stuff */ /* Setup kernel specific settings, e.g. allow broadcast ping, etc. */ run("/sbin/sysctl -e -p /etc/sysctl.conf >/dev/null"); /* Set initial hostname. */ set_hostname(hostname); ifconfig("lo", "127.0.0.1", "255.0.0.0", 1); if (network) run_interactive(network, "Starting networking: %s", network); umask(022); /* Hooks that rely on loopback, or basic networking being up. */ plugin_run_hooks(HOOK_NETWORK_UP); /* * Start all tasks/services in the configured runlevel */ svc_runlevel(cfglevel); _d("Running svc up hooks ..."); plugin_run_hooks(HOOK_SVC_UP); /* * Run startup scripts in /etc/finit.d/, if any. */ if (rcsd && fisdir(rcsd)) { _d("Running startup scripts in %s ...", rcsd); run_parts(rcsd, NULL); } /* Hooks that should run at the very end */ plugin_run_hooks(HOOK_SYSTEM_UP); /* * Enter main loop to monior /dev/initctl and services */ return run_loop(); }
int main() { fd_set rfds, wfds, readfds, writefds; int n; struct buf stdinbuf, stdoutbuf; slipconn sc; sig_setup(); login(&sc); setuid(0); /* set real uid to 0 for some ifconfig's */ slip_start(&sc); FD_ZERO(&rfds); FD_SET(sc.masterfd, &rfds); FD_SET(0, &rfds); FD_ZERO(&wfds); while (go) { readfds = rfds; writefds = wfds; n = select(sc.masterfd+1, &readfds, &writefds, 0, 0); if (n > 0) { if (FD_ISSET(0, &readfds)) { bufread(&sc, 0, &stdinbuf); if (stdinbuf.len == 0) { /* eof on stdin */ slip_stop(&sc); exit(0); } if (stdinbuf.len) { FD_SET(sc.masterfd, &wfds); FD_CLR(0, &rfds); } } if (FD_ISSET(sc.masterfd, &readfds)) { bufread(&sc, sc.masterfd, &stdoutbuf); if (stdoutbuf.len) { FD_SET(1, &wfds); FD_CLR(sc.masterfd, &rfds); } } if (FD_ISSET(sc.masterfd, &writefds)) { bufwrite(&sc, sc.masterfd, &stdinbuf); if (stdinbuf.len == 0) { FD_SET(0, &rfds); FD_CLR(sc.masterfd, &wfds); } } if (FD_ISSET(1, &writefds)) { bufwrite(&sc, 1, &stdoutbuf); if (stdoutbuf.len == 0) { FD_SET(sc.masterfd, &rfds); FD_CLR(1, &wfds); } } } } slip_stop(&sc); return 0; }
int main(int argc, char **argv) { int status = 0; struct sockaddr_in servaddr; int ret = 0; int server_port = 0; if (argc < 3) { fprintf (stderr, "Usage: %s <server_ip> <server_port>\n", argv[0]); assert (argc == 3); } // init_daemon(); // Enable this, to Daemonize the client server_port = atoi (argv[2]); if((status = creat_pidfile()) != 1) { syslog(LOG_ERR, "PID file could not be created...exiting"); doexit(EXIT_FAILURE); } sig_setup(); udpsock = socket(PF_INET, SOCK_DGRAM, 0); if (udpsock == -1) { syslog(LOG_ERR, "%s(): %s @ %d", __func__, strerror (errno), __LINE__); doexit(EXIT_FAILURE); } #if 1 memset((void *)&servaddr,'\0',sizeof(struct sockaddr_in)); servaddr.sin_family = AF_INET; servaddr.sin_port = htons(server_port); if ((servaddr.sin_addr.s_addr = pgethostbyname(argv[1])) < 0) { close(udpsock); syslog(LOG_ERR, "%s(): %s @ %d", __func__, strerror (errno), __LINE__); doexit(EXIT_FAILURE); } status = connect(udpsock, (struct sockaddr *) &servaddr ,sizeof(struct sockaddr_in)); if(status == -1) { syslog(LOG_ERR, "%s(): %s @ %d", __func__, strerror (errno), __LINE__); doexit(EXIT_FAILURE); } else #endif { ctx = dtls_setup_sslclient(); REDO: fprintf (stderr, "%s: %s(): Am here @ %d\n", __FILE__, __func__, __LINE__); ret = dtls_connect (); if (-1 == ret) goto END; else if (1 == ret) goto REDO; status = handle_data(ssl); if (status == -1) { syslog(LOG_ERR, "Unable to send beat : send failed[%s]...exiting", strerror(errno)); doexit(EXIT_FAILURE); } SSL_shutdown (ssl); } END: if (NULL != ssl) SSL_free (ssl); if (udpsock > 0) close(udpsock); closelog(); return 0; }
int main(int UNUSED(args), char *argv[]) { /* * Initial setup of signals, ignore all until we're up. */ sig_init(); /* * Mount base file system, kernel is assumed to run devtmpfs for /dev */ chdir("/"); umask(0); mount("none", "/proc", "proc", 0, NULL); mount("none", "/proc/bus/usb", "usbfs", 0, NULL); mount("none", "/sys", "sysfs", 0, NULL); mkdir("/dev/pts", 0755); mkdir("/dev/shm", 0755); mount("none", "/dev/pts", "devpts", 0, "gid=5,mode=620"); mount("none", "/dev/shm", "tmpfs", 0, NULL); umask(022); /* * Parse kernel parameters */ parse_kernel_cmdline(); cls(); echo("finit " VERSION " (built " __DATE__ " " __TIME__ " by " WHOAMI ")"); /* * Populate /dev and prepare for runtime events from kernel. */ #if defined(USE_UDEV) run_interactive("udevd --daemon", "Populating device tree"); #elif defined (MDEV) run_interactive(MDEV " -s", "Populating device tree"); #endif /* * Parse configuration file */ parse_finit_conf(FINIT_CONF); /* * Load plugins. Must run after finit.conf has registered * all services, or service plugins won't have anything to * hook on to. */ print_desc("", "Loading plugins"); print_result(plugin_load_all(PLUGIN_PATH)); /* * Mount filesystems */ _d("Mount filesystems in /etc/fstab ..."); #ifdef REMOUNT_ROOTFS_RW run("/bin/mount -n -o remount,rw /"); #endif #ifdef SYSROOT run(SYSROOT, "/", NULL, MS_MOVE, NULL); #endif _d("Root FS up, calling hooks ..."); plugin_run_hooks(HOOK_ROOTFS_UP); umask(0); run("/bin/mount -na"); run("/sbin/swapon -ea"); umask(0022); /* Cleanup stale files, if any still linger on. */ run_interactive("rm -rf /tmp/* /var/run/* /var/lock/*", "Cleanup temporary directories"); /* * Base FS up, enable standard SysV init signals */ sig_setup(); _d("Base FS up, calling hooks ..."); plugin_run_hooks(HOOK_BASEFS_UP); /* * Network stuff */ /* Setup kernel specific settings, e.g. allow broadcast ping, etc. */ run("/sbin/sysctl -e -p /etc/sysctl.conf >/dev/null"); /* Set initial hostname. */ set_hostname(hostname); ifconfig("lo", "127.0.0.1", "255.0.0.0", 1); if (network) run_interactive(network, "Starting networking: %s", network); umask(022); /* * Hooks that rely on loopback, or basic networking being up. */ plugin_run_hooks(HOOK_NETWORK_UP); /* * Start service monitor framework */ _d("Starting all static services from %s", FINIT_CONF); svc_start_all(); /* * Run startup scripts in /etc/finit.d/, if any. */ if (rcsd && fisdir(rcsd)) { _d("Running startup scripts in %s ...", rcsd); run_parts(rcsd, NULL); } /* * Hooks that should run at the very end */ plugin_run_hooks(HOOK_SYSTEM_UP); /* Start GETTY on console */ _d("Starting getty on console ..."); run_getty(GETTY, argv); /* * Enter main loop to monior /dev/initctl and services */ _d("Entering main loop ..."); return run_loop(); }