/* * Query the kernel about resource limit rules and print them out. */ static void show_rules(char *filter, int hflag, int nflag) { int error; char *outbuf = NULL; size_t filterlen, outbuflen = RCTL_DEFAULT_BUFSIZE / 4; if (filter != NULL) filterlen = strlen(filter) + 1; else filterlen = 0; do { outbuflen *= 4; outbuf = realloc(outbuf, outbuflen); if (outbuf == NULL) err(1, "realloc"); error = rctl_get_rules(filter, filterlen, outbuf, outbuflen); if (error && errno != ERANGE) err(1, "rctl_get_rules"); } while (error && errno == ERANGE); print_rules(outbuf, hflag, nflag); free(outbuf); }
int nk_snortconfig(int argc, char argv[4][ARGV_SIZE], char *retBuf, char *actionBuf, \ char *classBuf, char *sidBuf) { int cnt=0, idx, i; char *filename; /* Find any options. argc is at least 1 the argv[0] is the program name*/ argc--; argv++; idx = atoi(argv[2]); filename = argv[1]; /* Convert filename to lower case */ for (i=0; i<strlen(filename); i++) *(filename+i) |= 0x20; switch ( argv[0][1] ) { case 'p': cnt = print_rules(argv[1], idx, retBuf, actionBuf, classBuf, sidBuf); break; case 'm': cnt = set_rules_action(argv[1], idx, argv[3]); if (actionBuf==NULL) printf("Set rule Done !\n"); break; default : cnt = 0; } return cnt; }
int exec_opt(t_option *option, int ac, char **av) { int (*funct_tab[5])(t_option *option, char **av, int *i) = { &opt_p, &opt_y, &opt_x, &opt_f, &opt_h }; int i; int j; int cool; i = 1; cool = 0; while (i < ac) { j = find_opt(av[i]); if (j >= 5) print_rules(&cool); else funct_tab[j](option, av, &i); ++i; } return (0); }
void main() { print_rules(); // production rules printf("Input string(ex. aabbccd) = "); ch = getchar(); // input string: "aabbbccd" pS(); if (!errflag && ch==END) puts("OK"); else error(); }
void intro(int x) { do { printf("Welcome to Yahtzee!\n1. Read rules\n2. Play Yahtzee\n3. Exit\n"); scanf("%d", &x); switch (x) { case 1: print_rules(); break; case 2: break; case 3: printf("See you later!\n"); return 0; default: printf("Command not recognized. Please enter an integer between 1 and 3.\n"); break; } } while (x != 2 && x != 3); //Runs while x = 1 so the player can reselect 1 or 3 }
char menu() { char choice; printf("N=New Game, R=Rules, Q=Quit\n" ); scanf("%c",&choice); getchar(); choice = tolower(choice); if (choice == 'n') { game(); } else if(choice == 'r') { print_rules(); } else if(choice == 'q') { exit(0); } }
static int fractol_core(t_fol *f) { do_key(f); if (out_limits(f)) exit(0); f->step = 1 / f->zoom; f->def_min.x = -f->mid.x / f->zoom; f->def_min.y = -f->mid.y / f->zoom; f->def_max.x = (WIN_H - f->mid.x) / f->zoom; f->def_max.y = (WIN_W - f->mid.y) / f->zoom; print_rules(f); print_param(f); if (f->type == 'j') julia(f); else if (f->type == 'b') buddha(f); else if (f->type == 'B') buddha2(f); else mandelbrot(f); mlx_put_image_to_window(f->mlx, f->win, f->im, 0, 0); return (1); }
int main(int argc, char *argv[]) { char *label = NULL; char *user = NULL; char *subject = NULL, *object = NULL, *access = NULL; enum action { ACT_NONE, ACT_SET, ACT_GET, ACT_FLUSH, ACT_PRINT, ACT_RULE, ACT_USER, ACT_HELP, } action = ACT_NONE; int opt; getopt_init(); while (-1 != (opt = getopt(argc, argv, "S:GFPR:U:o:a:h"))) { enum action act = ACT_NONE; switch(opt) { case 'S': act = ACT_SET; label = optarg; break; case 'G': act = ACT_GET; break; case 'F': act = ACT_FLUSH; break; case 'P': act = ACT_PRINT; break; case 'R': act = ACT_RULE; subject = optarg; break; case 'U': act = ACT_USER; user = optarg; label = argv[optind++]; break; case 'o': object = optarg; break; case 'a': access = optarg; break; case 'h': act = ACT_HELP; break; default: printf("Unknown argument -- %c\n", optopt); return -EINVAL; } if (act != ACT_NONE) { if (action != ACT_NONE) { printf("Incorrect commmand line, multiplie action specified\n"); return -EINVAL; } action = act; } } switch(action) { case ACT_SET: return smac_labelset(label); case ACT_GET: return print_label(optind < argc ? argv[optind] : NULL); case ACT_FLUSH: return smac_flushenv(); case ACT_RULE: return new_rule(subject, object, access); case ACT_PRINT: return print_rules(); case ACT_USER: return cmd_smac_adm_user_set(user, label); case ACT_NONE: default: break; } return 0; }
int main(int argc, char *argv[]) { int ret = 0; #ifndef RUN_STANDALONE openlog("xcpmd", 0, LOG_DAEMON); daemonize(); #endif xcpmd_log(LOG_INFO, "Starting XenClient power management daemon.\n"); //Initialize libevent library event_init(); //Initialize xenstore. if (xenstore_init() == -1) { xcpmd_log(LOG_ERR, "Unable to init xenstore\n"); return -1; } // Allow everyone to read from /pm/ in xenstore xenstore_rm("/pm"); xenstore_mkdir("/pm"); xenstore_chmod("r0", 1, "/pm"); initialize_platform_info(); xcpmd_log(LOG_INFO, "Starting DBUS server.\n"); if (xcpmd_dbus_initialize() == -1) { xcpmd_log(LOG_ERR, "Failed to initialize DBUS server\n"); goto xcpmd_err; } xcpmd_log(LOG_INFO, "Starting ACPI events monitor.\n"); if (acpi_events_initialize() == -1) { xcpmd_log(LOG_ERR, "Failed to initialize ACPI events monitor\n"); goto xcpmd_err; } // Load modules xcpmd_log(LOG_INFO, "Loading modules.\n"); if (init_modules() == -1) { xcpmd_log(LOG_ERR, "Failed to load all modules\n"); goto xcpmd_err; } //This relies on both acpi-events and acpi-module having been initialized xcpmd_log(LOG_INFO, "Initializing ACPI state.\n"); acpi_initialize_state(); // Load policy xcpmd_log(LOG_INFO, "Loading policy.\n"); if (load_policy_from_db() == -1) { xcpmd_log(LOG_WARNING, "Error loading policy from DB; continuing...\n"); } #ifdef POLICY_FILE_PATH if (load_policy_from_file(POLICY_FILE_PATH) == -1) { xcpmd_log(LOG_WARNING, "Error loading policy from file %s; continuing...\n", POLICY_FILE_PATH); } #endif #ifdef XCPMD_DEBUG xcpmd_log(LOG_DEBUG, "Rules loaded:\n"); print_rules(); #endif xcpmd_log(LOG_INFO, "Entering event loop.\n"); event_dispatch(); goto xcpmd_out; xcpmd_err: ret = -1; xcpmd_out: uninit_modules(); acpi_events_cleanup(); xcpmd_dbus_cleanup(); #ifndef RUN_STANDALONE closelog(); #endif return ret; }
int /* O - Exit status */ main(int argc, /* I - Number of command-line args */ char *argv[]) /* I - Command-line arguments */ { int i; /* Looping vars */ const char *filter_path; /* Filter path */ char super[MIME_MAX_SUPER], /* Super-type name */ type[MIME_MAX_TYPE]; /* Type name */ int compression; /* Compression of file */ int cost; /* Cost of filters */ mime_t *mime; /* MIME database */ mime_type_t *src, /* Source type */ *dst; /* Destination type */ struct stat srcinfo; /* Source information */ ppd_file_t *ppd; /* PPD file */ cups_array_t *filters; /* Filters for the file */ mime_filter_t *filter; /* Current filter */ mime = NULL; src = NULL; dst = NULL; ppd = NULL; filter_path = "../filter:" CUPS_SERVERBIN "/filter"; srcinfo.st_size = 0; for (i = 1; i < argc; i ++) if (!strcmp(argv[i], "-d")) { i ++; if (i < argc) { mime = mimeLoad(argv[i], filter_path); if (ppd) add_ppd_filters(mime, ppd); } } else if (!strcmp(argv[i], "-f")) { i ++; if (i < argc) filter_path = argv[i]; } else if (!strcmp(argv[i], "-p")) { i ++; if (i < argc) { ppd = ppdOpenFile(argv[i]); if (mime) add_ppd_filters(mime, ppd); } } else if (!src) { if (!mime) mime = mimeLoad("../conf", filter_path); if (ppd) add_ppd_filters(mime, ppd); src = mimeFileType(mime, argv[i], NULL, &compression); stat(argv[i], &srcinfo); if (src) printf("%s: %s/%s%s\n", argv[i], src->super, src->type, compression ? " (gzipped)" : ""); else if ((src = mimeType(mime, "application", "octet-stream")) != NULL) printf("%s: application/octet-stream\n", argv[i]); else { printf("%s: unknown\n", argv[i]); if (mime) mimeDelete(mime); return (1); } } else { sscanf(argv[i], "%15[^/]/%31s", super, type); dst = mimeType(mime, super, type); filters = mimeFilter2(mime, src, srcinfo.st_size, dst, &cost); if (!filters) { printf("No filters to convert from %s/%s to %s.\n", src->super, src->type, argv[i]); } else { int first = 1; /* First filter shown? */ printf("Filter cost = %d\n", cost); for (filter = (mime_filter_t *)cupsArrayFirst(filters); filter; filter = (mime_filter_t *)cupsArrayNext(filters)) { if (!strcmp(filter->filter, "-")) continue; if (first) { first = 0; fputs(filter->filter, stdout); } else printf(" | %s", filter->filter); } putchar('\n'); cupsArrayDelete(filters); } } if (!mime) { mime = mimeLoad("../conf", filter_path); if (ppd) add_ppd_filters(mime, ppd); } if (!src) { puts("MIME database types:"); for (src = mimeFirstType(mime); src; src = mimeNextType(mime)) { printf("\t%s/%s (%d):\n", src->super, src->type, src->priority); print_rules(src->rules); puts(""); } puts(""); puts("MIME database filters:"); for (filter = mimeFirstFilter(mime); filter; filter = mimeNextFilter(mime)) printf("\t%s/%s to %s/%s: %s (%d)\n", filter->src->super, filter->src->type, filter->dst->super, filter->dst->type, filter->filter, filter->cost); type_dir(mime, "../doc"); } return (0); }
static void print_rules(mime_magic_t *rules) /* I - Rules to print */ { int i; /* Looping var */ static char indent[255] = "\t"; /* Indentation for rules */ if (rules == NULL) return; while (rules != NULL) { printf("%s[%p] ", indent, rules); if (rules->invert) printf("NOT "); switch (rules->op) { case MIME_MAGIC_MATCH : printf("match(%s)", rules->value.matchv); break; case MIME_MAGIC_LOCALE : printf("locale(%s)", rules->value.localev); break; case MIME_MAGIC_ASCII : printf("ascii(%d,%d)", rules->offset, rules->length); break; case MIME_MAGIC_PRINTABLE : printf("printable(%d,%d)", rules->offset, rules->length); break; case MIME_MAGIC_STRING : printf("string(%d,", rules->offset); for (i = 0; i < rules->length; i ++) if (rules->value.stringv[i] < ' ' || rules->value.stringv[i] > 126) printf("<%02X>", rules->value.stringv[i]); else putchar(rules->value.stringv[i]); putchar(')'); break; case MIME_MAGIC_CHAR : printf("char(%d,%d)", rules->offset, rules->value.charv); break; case MIME_MAGIC_SHORT : printf("short(%d,%d)", rules->offset, rules->value.shortv); break; case MIME_MAGIC_INT : printf("int(%d,%d)", rules->offset, rules->value.intv); break; case MIME_MAGIC_CONTAINS : printf("contains(%d,%d,", rules->offset, rules->region); for (i = 0; i < rules->length; i ++) if (rules->value.stringv[i] < ' ' || rules->value.stringv[i] > 126) printf("<%02X>", rules->value.stringv[i]); else putchar(rules->value.stringv[i]); putchar(')'); break; default : break; } if (rules->child != NULL) { if (rules->op == MIME_MAGIC_OR) puts("OR ("); else puts("AND ("); strcat(indent, "\t"); print_rules(rules->child); indent[strlen(indent) - 1] = '\0'; printf("%s)\n", indent); } else putchar('\n'); rules = rules->next; } }
int main (int argc, char **argv) { GOptionContext *context; GError *error = NULL; int ret; static gboolean opt_packages = FALSE; static gboolean opt_rules = FALSE; static gboolean opt_version = FALSE; static gchar *opt_interactive = NULL; static GOptionEntry entries[] = { { "interact", 0, 0, G_OPTION_ARG_STRING, &opt_interactive, "Interact with the raw protocol", "boundary" }, { "packages", 0, 0, G_OPTION_ARG_NONE, &opt_packages, "Show Cockpit package information", NULL }, { "rules", 0, 0, G_OPTION_ARG_NONE, &opt_rules, "Show Cockpit bridge rules", NULL }, { "version", 0, 0, G_OPTION_ARG_NONE, &opt_version, "Show Cockpit version information", NULL }, { NULL } }; signal (SIGPIPE, SIG_IGN); /* Debugging issues during testing */ #if WITH_DEBUG signal (SIGABRT, cockpit_test_signal_backtrace); signal (SIGSEGV, cockpit_test_signal_backtrace); #endif g_setenv ("GSETTINGS_BACKEND", "memory", TRUE); g_setenv ("GIO_USE_PROXY_RESOLVER", "dummy", TRUE); g_setenv ("GIO_USE_VFS", "local", TRUE); /* * All channels that are added here should * not rely on running as a real user, however * they may lookup paths, such as run dir or * home directory. Glib has problems if * g_get_user_database_entry is called without * a real user, which it's path functions * do as a last resort when no environment vars * are set. So set HOME if it isn't set.. */ g_setenv("HOME", "/", FALSE); context = g_option_context_new (NULL); g_option_context_add_main_entries (context, entries, NULL); g_option_context_set_description (context, "cockpit-stub provides a limited number of channels and is meant to be" "used in place of cockpit-bridge in non-system setting. When\n" "run from the command line one of the options above must be specified.\n"); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (error) { g_printerr ("cockpit-stub: %s\n", error->message); g_error_free (error); return 1; } if (opt_packages) { cockpit_packages_dump (); return 0; } else if (opt_rules) { print_rules (); return 0; } else if (opt_version) { print_version (); return 0; } if (!opt_interactive && isatty (1)) { g_printerr ("cockpit-stub: no option specified\n"); return 2; } ret = run_bridge (opt_interactive); if (packages) cockpit_packages_free (packages); g_free (opt_interactive); return ret; }
int main(int argc, char *argv[]) { signal (SIGINT, signal_handler); //printf("\033[?1049h\033[H"); clear_log(); my_log("Software switch starting..."); my_log(pcap_lib_version()); int option = 0, ret; char c; pthread_t config_thread; char errbuf[PCAP_ERRBUF_SIZE]; p1 = create_port_struct(1); p2 = create_port_struct(2); while ((option = getopt(argc, argv,"h l 1:2: m")) != -1) { switch (option) { case '1' : strcpy(p1->name, optarg); break; case '2' : strcpy(p2->name, optarg); break; case 'l': list_interfaces(); exit(0); case 'm': mock_rule(); break; case 'h': default: print_usage(); exit(EXIT_FAILURE); } } p1->handle = pcap_create(p1->name, errbuf); if ( (ret = pcap_setdirection(p1->handle, PCAP_D_IN)) != 0){ printf("pcap_setdirection returned %i\n", ret); my_log("pcap_setdirection failed"); pcap_perror(p1->handle, 0); //exit(-1); } if ( pcap_set_promisc(p1->handle, 1) != 0){ printf("pcap_set_promisc returned \n%s\n", pcap_geterr(p1->handle)); my_log("pcap_set_promisc failed"); pcap_perror(p1->handle, 0); exit(-1); } if ( pcap_set_immediate_mode(p1->handle, 1) != 0){ printf("pcap_set_immediate_mode returned \n%s\n", pcap_geterr(p1->handle)); my_log("pcap_set_immediate_mode failed"); pcap_perror(p1->handle, 0); exit(-1); } if ( pcap_activate(p1->handle)){ printf("Failed to open interface %s\n", pcap_geterr(p1->handle)); exit(-1); } else { sprintf(log_b, "Handle activated for %s", p1->name); my_log(log_b); } p2->handle = pcap_create(p2->name, errbuf); if ( pcap_setdirection(p2->handle, PCAP_D_OUT) != 0){ my_log("pcap_setdirection failed"); pcap_perror(p2->handle, 0); //exit(-1); } if ( pcap_set_promisc(p2->handle, 1) != 0){ my_log("pcap_set_promisc failed"); pcap_perror(p2->handle, 0); exit(-1); } if ( pcap_set_immediate_mode(p2->handle, 1) != 0){ my_log("pcap_set_immediate_mode failed"); pcap_perror(p2->handle, 0); exit(-1); } if ( pcap_activate(p2->handle)){ printf("Failed to open interface %s\n", pcap_geterr(p2->handle)); exit(-1); } else { sprintf(log_b, "Handle activated for %s", p2->name); my_log(log_b); } //exit(0); my_log("Deleting mac table.."); clear_mac(); sprintf(log_b, "Default action is %s", (DEFAULT_ACTION == R_ALLOW)? "R_ALLOW" : "R_DENY"); my_log(log_b); my_log("Creating threads..."); pthread_mutex_init(&mutex, NULL); if ( pthread_create(&(p1->thread), 0, port_listener, (void *)p1) ){ my_log("Error creating p1 thread"); exit(-1); } if ( pthread_create(&(p2->thread), 0, port_listener, (void *)p2) ){ my_log("Error creating p2 thread"); exit(-1); } pthread_create(&config_thread, 0, config, 0); while (1) { mac_delete_old_entries(5); if(pause_rendering == 1) continue; // render here system("clear"); print_mac(); print_rules(); print_stats_header(); print_stats(p1->in, "1 IN"); print_stats(p1->out, "1 OUT"); print_stats(p2->in, "2 IN"); print_stats(p2->out, "2 OUT"); printf("p1in: %i\tp1out: %i\tp2in: %i\tp2out: %i\n", p1in, p1out, p2in, p2out); sleep(1); } pthread_join(config_thread, 0); pthread_join(p1->thread, 0); pthread_join(p2->thread, 0); //printf("\033[?1049l"); // go back return 0; }