/* * This function replaces sys/dev/cninit.c * Determine which device is the console using * the PROM "input source" and "output sink". */ void cninit(void) { struct sunromvec *v; struct zschan *zc; struct consdev *cn; int channel, zs_unit, zstty_unit; uint8_t inSource, outSink; extern const struct cdevsw zstty_cdevsw; /* Get the zs driver ready for console duty. */ zs_init(); v = romVectorPtr; inSource = *v->inSource; outSink = *v->outSink; if (inSource != outSink) { mon_printf("cninit: mismatched PROM output selector\n"); } switch (inSource) { default: mon_printf("cninit: invalid inSource=%d\n", inSource); sunmon_abort(); inSource = 0; /* fall through */ case 0: /* keyboard/display */ #if NKBD > 0 zs_unit = 0; channel = 0; cn = &consdev_kd; /* Set cn_dev, cn_pri in kd.c */ break; #else /* NKBD */ mon_printf("cninit: kdb/display not configured\n"); sunmon_abort(); inSource = 1; /* fall through */ #endif /* NKBD */ case 1: /* ttya */ case 2: /* ttyb */ case 3: /* ttyc (rewired keyboard connector) */ case 4: /* ttyd (rewired mouse connector) */ zstty_unit = inSource - 1; zs_unit = zstty_conf[zstty_unit].zs_unit; channel = zstty_conf[zstty_unit].channel; cn = &consdev_tty; cn->cn_dev = makedev(cdevsw_lookup_major(&zstty_cdevsw), zstty_unit); cn->cn_pri = CN_REMOTE; break; } /* Now that inSource has been validated, print it. */ mon_printf("console is %s\n", prom_inSrc_name[inSource]); zc = zs_get_chan_addr(zs_unit, channel); if (zc == NULL) { mon_printf("cninit: zs not mapped.\n"); return; } zs_conschan = zc; zs_hwflags[zs_unit][channel] = ZS_HWFLAG_CONSOLE; cn_tab = cn; (*cn->cn_init)(cn); #ifdef KGDB zs_kgdb_init(); #endif }
int main( int argc, char* argv[ ] ) { int ret = EXIT_SUCCESS; int make_daemon = 1, daemon_flags = 0; bool force_stop = false; /////////////////////////////////////////////// // parse command line options int i; for ( i = 1; i < argc; i++ ) { if ( argv[i][0] != '-' ) break; if ( strcmp( argv[i], "--no-daemon" ) == 0 ) make_daemon = 0; else if ( strcmp( argv[i], "--force" ) == 0 ) { daemon_flags |= D_NOLOCKCHECK; force_stop = true; } else if ( strcmp( argv[i], "--no-lockfile" ) == 0 ) { daemon_flags |= D_NOLOCKFILE; } else { if ( strcmp( argv[i], "--help" ) != 0 && strcmp( argv[i], "-h" ) != 0 ) printf( "\nUnknown Option: %s\n", argv[i] ); print_usage(); exit(0); } } if ( i == argc ) { print_usage(); exit(0); } if ( i != argc - 1 ) { printf( "Error: Invalid Command\n\n" ); print_usage(); exit(0); } // parse command line commands if ( strcmp( argv[i], "start" ) != 0 ) { if ( strcmp( argv[i], "stop" ) == 0 ) { if ( !daemon_stop( force_stop ) ) exit( EXIT_FAILURE ); exit( EXIT_SUCCESS ); } else if ( strcmp( argv[i], "restart" ) == 0 ) { if ( !daemon_stop( force_stop ) ) exit( EXIT_FAILURE ); } else { printf( "Error: Unknown Command: %s\n\n", argv[i] ); print_usage(); exit(0); } } ///////////////////////////////////////////////// if ( make_daemon ) { if ( !daemon_init( daemon_flags ) ) { exit(0); } } zcnf_daemon_t* daemon_cnf = zcnf_daemon_load(); if ( !daemon_cnf ) { fprintf( stderr, "failed to load config.\n" ); exit( EXIT_FAILURE ); } // Trap SIGPIPE signal( SIGPIPE, signal_handler ); // call any needed library init functions website_init(); zs_init( daemon_cnf->ssl_cert_path, daemon_cnf->ssl_key_path ); memset( connections, 0, sizeof( connections ) ); for ( i = 0; i < daemon_cnf->n; i++ ) { int sockfd = zsocket( inet_addr( daemon_cnf->proxies[ i ].ip ), daemon_cnf->proxies[ i ].port, ZSOCK_LISTEN, insock_event_hdlr, false ); if ( sockfd == -1 ) { ret = EXIT_FAILURE; fprintf( stderr, "Proxy failed on %s:%d\n", daemon_cnf->proxies[ i ].ip, daemon_cnf->proxies[ i ].port ); goto quit; } zs_set_read( sockfd ); printf( " * started listening on %s:%d\n", daemon_cnf->proxies[ i ].ip, daemon_cnf->proxies[ i ].port ); } FL_SET( daemon_flags, D_KEEPSTDIO ); #if defined(DEBUG) FL_SET( daemon_flags, D_NOCD ); setlogmask( LOG_UPTO( LOG_DEBUG ) ); openlog( DAEMON_NAME, LOG_CONS | LOG_NDELAY | LOG_PERROR | LOG_PID, LOG_USER ); #else setlogmask( LOG_UPTO( LOG_INFO ) ); openlog( DAEMON_NAME, LOG_CONS, LOG_USER ); #endif // daemonize if ( make_daemon ) { if ( !daemon_detach( daemon_flags ) ) { ret = EXIT_FAILURE; goto quit; } } #ifndef DEBUG daemon_redirect_stdio(); #endif syslog( LOG_INFO, "initialized." ); // starts a select() loop and calls // the associated file descriptor handlers // when they are ready to read/write do { do { msg_switch_select(); zs_select(); } while ( msg_switch_need_select() || zs_need_select() ); } while ( zfd_select(2) ); quit: // cleanup zcnf_daemon_free( daemon_cnf ); if ( ret == EXIT_FAILURE ) { syslog( LOG_INFO, "exit: failure" ); } else { syslog( LOG_INFO, "exit: success" ); } closelog(); return ret; }
int main (int argc, char *argv[]) { ZIPstream *zstream = NULL; ZIPentry *zentry = NULL; uint64_t buffersize = 0; ssize_t writestatus; time_t now; int method = ZS_DEFLATE; int fd; int idx; if ( argc < 2 ) { fprintf (stderr, "zipexample: write a ZIP archive to stdout from memory buffer\n"); fprintf (stderr, "Usage: zipexample [-S] [-D] > output.zip\n"); fprintf (stderr, " -S Store archive entries\n"); fprintf (stderr, " -D Deflate archive entries\n"); fprintf (stderr, "\n"); fprintf (stderr, "One of -S or -D is required, make sure to redirect stdout."); fprintf (stderr, "\n"); return 0; } /* Loop through input arguments and process options */ for ( idx=1; idx < argc; idx++ ) { if ( ! strncmp (argv[idx], "-S", 2) ) { method = ZS_STORE; fprintf (stderr, "Storing archive entries, no compression\n"); continue; } else if ( ! strncmp (argv[idx], "-D", 2) ) { method = ZS_DEFLATE; fprintf (stderr, "Deflating archive entries, no compression\n"); continue; } } /* Set output stream to stdout */ fd = fileno (stdout); /* Initialize ZIP container, skip options */ if ( (zstream = zs_init (fd, NULL)) == NULL ) { fprintf (stderr, "Error initializing ZIP archive\n"); return 1; } buffersize = strlen (buffer); now = time(NULL); /* Write entry containing buffer contents */ zentry = zs_writeentry (zstream, (unsigned char *)buffer, buffersize, "Leon.txt", now, method, &writestatus); if ( zentry == NULL ) { fprintf (stderr, "Error adding entry to output ZIP (writestatus: %lld)\n", (long long int) writestatus); return 1; } fprintf (stderr, "Added %s: %lld -> %lld (%.1f%%)\n", zentry->Name, (long long int) zentry->UncompressedSize, (long long int) zentry->CompressedSize, (100.0 * zentry->CompressedSize / zentry->UncompressedSize)); /* Write another entry containing the same buffer contents */ zentry = zs_writeentry (zstream, (unsigned char *)buffer, buffersize, "Deckard.txt", now, method, &writestatus); if ( zentry == NULL ) { fprintf (stderr, "Error adding entry to output ZIP (writestatus: %lld)\n", (long long int) writestatus); return 1; } fprintf (stderr, "Added %s: %lld -> %lld (%.1f%%)\n", zentry->Name, (long long int) zentry->UncompressedSize, (long long int) zentry->CompressedSize, (100.0 * zentry->CompressedSize / zentry->UncompressedSize)); /* Many more files/entries can be added to the ZIP archive ... */ /* Finish ZIP archive */ if ( zs_finish (zstream, &writestatus) ) { fprintf (stderr, "Error finishing ZIP archive (writestatus: %lld)\n", (long long int) writestatus); return 1; } fprintf (stderr, "Success, created archive with %d entries\n", zstream->EntryCount); /* Cleanup */ zs_free (zstream); return 0; }
int main(int argc, char *argv[]) { static const struct option options[] = { { "version", no_argument, 0, 'V' }, { "help", no_argument, 0, 'h' }, { NULL } }; int opt = 0; int index = 0; while ((opt = getopt_long(argc, argv, "Vh", options, &index)) != -1) { switch (opt) { case 'V': printf("rosedb_tool (Knot DNS), version %s\n", PACKAGE_VERSION); return EXIT_SUCCESS; case 'h': help(stdout); return EXIT_SUCCESS; default: help(stderr); return EXIT_FAILURE; } } if (argc < 3) { help(stderr); return EXIT_FAILURE; } /* Get mandatory parameters. */ int ret = EXIT_SUCCESS; char *dbdir = argv[1]; char *action = argv[2]; argv += 3; argc -= 3; g_scanner = malloc(sizeof(zs_scanner_t)); if (g_scanner == NULL) { return EXIT_FAILURE; } if (zs_init(g_scanner, ".", KNOT_CLASS_IN, 0) != 0 || zs_set_processing(g_scanner, NULL, parse_err, NULL) != 0) { zs_deinit(g_scanner); free(g_scanner); return EXIT_FAILURE; } /* Open cache for operations. */ struct cache *cache = cache_open(dbdir, 0, NULL); if (cache == NULL) { fprintf(stderr, "failed to open db '%s'\n", dbdir); zs_deinit(g_scanner); free(g_scanner); return EXIT_FAILURE; } /* Execute action. */ bool found = false; for (unsigned i = 0; i < TOOL_ACTION_COUNT; ++i) { struct tool_action *ta = &TOOL_ACTION[i]; if (strcmp(ta->name, action) == 0) { /* Check param count. */ if (argc < ta->min_args) { break; } /* Now set as found. */ found = true; MDB_txn *txn = NULL; int ret = mdb_txn_begin(cache->env, NULL, 0, &txn); if (ret != MDB_SUCCESS) { fprintf(stderr, "failed to open transaction, aborting\n"); break; } /* Execute operation handler. */ ret = ta->func(cache, txn, argc, argv); if (ret != 0) { fprintf(stderr, "'%s' failed, aborting transaction\n", action); mdb_txn_abort(txn); } else { mdb_txn_commit(txn); } break; } } cache_close(cache); zs_deinit(g_scanner); free(g_scanner); if (!found) { help(stderr); return EXIT_FAILURE; } return ret; }