int cli_main(int argc, char* argv[]) { time_t start; time_t next; struct crontab c; str jobstr; msg_debug_init(); timespec_next_init(); memset(&c, 0, sizeof c); jobstr.len = strlen(jobstr.s = argv[0]); jobstr.size = 0; if (!crontab_parse(&c, &jobstr, "nobody") || c.jobs == 0) usage(111, "Invalid crontab line"); if ((start = strtol(argv[1], 0, 10)) <= 0) usage(111, "Invalid timesstamp"); next = timespec_next(&c.jobs->times, start, localtime(&start)); obuf_put5s(&outbuf, "last: ", utoa(start), " ", fmttime(start), "\n"); obuf_put5s(&outbuf, "next: ", utoa(next), " ", fmttime(next), "\n"); obuf_flush(&outbuf); return 0; (void)argc; }
int main(int argc, char* argv[]) { struct connection conn; iopoll_fd fds[2]; int selfpipe; int i; msg_debug_init(); testmode = getenv("TESTMODE") != 0; if ((shell_argv = malloc((argc + 3) * sizeof *argv)) == 0) die_oom(111); for (i = 1; i < argc; ++i) shell_argv[i-1] = argv[i]; for (; i < argc + 4; ++i) shell_argv[i-1] = 0; shell_argc = argc - 1; if ((path = getenv("PATH")) == 0) die1(111, "No PATH is set"); if ((devnull = open("/dev/null", O_RDWR)) == -1) die1sys(111, "Could not open \"/dev/null\""); if (!nonblock_on(0)) die1sys(111, "Could not set non-blocking status"); if ((selfpipe = selfpipe_init()) == -1) die1sys(111, "Could not create self-pipe"); init_slots(); connection_init(&conn, 0, 0); fds[0].fd = 0; fds[0].events = IOPOLL_READ; fds[1].fd = selfpipe; fds[1].events = IOPOLL_READ; for (;;) { if (iopoll_restart(fds, 2, -1) == -1) die1sys(111, "Poll failed"); if (fds[0].revents) if (connection_read(&conn, handle_packet) <= 0) break; if (fds[1].revents) { read(selfpipe, &i, 1); handle_child(WNOHANG); } } msg1("Waiting for remaining slots to complete"); while (slots_used > 0) handle_child(0); return 0; }
int cli_main(int argc, char* argv[]) { const char* server_name = 0; const char* env; msg_debug_init(); encr_start(); prep_sender(); service = argv[0]; if (argc > 1 && argv[1][0] != '-' && argv[1][0] != '+') { server_name = argv[1]; ++argv; --argc; } if (argc > 1) load_patterns(argv + 1); if (server_name == 0 && (server_name = getenv("SERVER")) == 0) die1(1, "Server address not named on command line nor in $SERVER"); if (!resolve_ipv4name(server_name, &ip)) die3(1, "Could not resolve '", server_name, "'"); brandom_init(); if ((env = getenv("KEYDIR")) != 0) keydir = env; load_keys(server_name); if ((env = getenv("PORT")) != 0) port = strtoul(env, 0, 10); if (port == 0) port = 11014; if ((sock = socket_udp()) == -1) die1sys(1, "Could not create UDP socket"); if (!socket_connect4(sock, &ip, port)) die1sys(1, "Could not bind socket"); if (!str_ready(&packet, 65535) || !str_ready(&rpacket, 4+4+8+256*5)) die1(1, "Out of memory"); getenvu("ACK_TIMEOUT", &ack_timeout); getenvu("CID_TIMEOUT", &cid_timeout); getenvu("RETRANSMITS", &retransmits); getenvu("READWAIT", &readwait); getenvu("STARTLINES", &startlines); if (getenv("EXITONEOF") != 0) exitoneof = 1; if (getenv("NOFILES") == 0 && getenv("NOFILE") == 0) buffer = buffer_file_init(); else buffer = buffer_nofile_init(); sig_all_catch(sigfn); exitasap = 0; mainloop(); return 0; }