int mkdir_main (int argc, char **argv) { mode_t mode = (mode_t)(-1); int status = EXIT_SUCCESS; int flags = 0; unsigned long opt; char *smode; #ifdef CONFIG_SELINUX security_context_t scontext = NULL; #endif #if ENABLE_FEATURE_MKDIR_LONG_OPTIONS bb_applet_long_options = mkdir_long_options; #endif #ifdef CONFIG_SELINUX opt = bb_getopt_ulflags(argc, argv, "m:pZ:", &smode, &scontext); #else opt = bb_getopt_ulflags(argc, argv, "m:p", &smode); #endif if(opt & 1) { mode = 0777; if (!bb_parse_mode (smode, &mode)) { bb_error_msg_and_die ("invalid mode `%s'", smode); } } if(opt & 2) flags |= FILEUTILS_RECUR; #ifdef CONFIG_SELINUX if(opt & 4) { if(!is_selinux_enabled()) { bb_error_msg_and_die ("Sorry, --context (-Z) can be used only on " "a selinux-enabled kernel.\n" ); } if (setfscreatecon(scontext)) { bb_error_msg_and_die ("Sorry, cannot set default context " "to %s.\n", scontext); } } #endif if (optind == argc) { bb_show_usage(); } argv += optind; do { if (bb_make_directory(*argv, mode, flags)) { status = EXIT_FAILURE; } } while (*++argv); return status; }
int chgrp_main(int argc, char **argv) { long gid; int recursiveFlag; int retval = EXIT_SUCCESS; char *p; recursiveFlag = bb_getopt_ulflags(argc, argv, "R"); if (argc - optind < 2) { bb_show_usage(); } argv += optind; /* Find the selected group */ gid = strtoul(*argv, &p, 10); /* maybe it's already numeric */ if (*p || (p == *argv)) { /* trailing chars or nonnumeric */ gid = my_getgrnam(*argv); } ++argv; /* Ok, ready to do the deed now */ do { if (! recursive_action (*argv, recursiveFlag, FALSE, FALSE, fileAction, fileAction, &gid)) { retval = EXIT_FAILURE; } } while (*++argv); return retval; }
extern int rm_main(int argc, char **argv) { int status = 0; int flags = 0; unsigned long opt; bb_opt_complementaly = "f-i:i-f"; opt = bb_getopt_ulflags(argc, argv, "fiRr"); if(opt & 1) flags |= FILEUTILS_FORCE; if(opt & 2) flags |= FILEUTILS_INTERACTIVE; if(opt & 12) flags |= FILEUTILS_RECUR; if (*(argv += optind) != NULL) { do { const char *base = bb_get_last_path_component(*argv); if ((base[0] == '.') && (!base[1] || ((base[1] == '.') && !base[2]))) { bb_error_msg("cannot remove `.' or `..'"); } else if (remove_file(*argv, flags) >= 0) { continue; } status = 1; } while (*++argv); } else if (!(flags & FILEUTILS_FORCE)) { bb_show_usage(); } return status; }
/* * addgroup will take a login_name as its first parameter. * * gid * * can be customized via command-line parameters. * ________________________________________________________________________ */ int addgroup_main(int argc, char **argv) { char *group; char *user; gid_t gid = 0; /* get remaining args */ if(bb_getopt_ulflags(argc, argv, "g:", &group)) { gid = strtol(group, NULL, 10); } if (optind < argc) { group = argv[optind]; optind++; } else { bb_show_usage(); } if (optind < argc) { user = argv[optind]; optind++; } else { user = ""; } if_i_am_not_root(); /* werk */ return addgroup(bb_path_group_file, group, gid, user); }
int chgrp_main(int argc, char **argv) { long gid; int recursiveFlag; int retval = EXIT_SUCCESS; recursiveFlag = bb_getopt_ulflags(argc, argv, "R"); if (argc - optind < 2) { bb_show_usage(); } argv += optind; /* Find the selected group */ gid = get_ug_id(*argv, my_getgrnam); ++argv; /* Ok, ready to do the deed now */ do { if (! recursive_action (*argv, recursiveFlag, FALSE, FALSE, fileAction, fileAction, &gid)) { retval = EXIT_FAILURE; } } while (*++argv); return retval; }
int dos2unix_main(int argc, char *argv[]) { int ConvType; int o; /* See if we are supposed to be doing dos2unix or unix2dos */ if (argv[0][0]=='d') { ConvType = CT_DOS2UNIX; /*2*/ } else { ConvType = CT_UNIX2DOS; /*1*/ } /* -u and -d are mutally exclusive */ bb_opt_complementally = "?:u--d:d--u"; /* process parameters */ /* -u convert to unix */ /* -d convert to dos */ o = bb_getopt_ulflags(argc, argv, "du"); /* Do the conversion requested by an argument else do the default * conversion depending on our name. */ if (o) ConvType = o; if (optind < argc) { while(optind < argc) if ((o = convert(argv[optind++], ConvType)) < 0) break; } else o = convert(NULL, ConvType); return o; }
int watchdog_main(int argc, char **argv) { char *t_arg; unsigned long flags; flags = bb_getopt_ulflags(argc, argv, "t:", &t_arg); if (flags & 1) timer_duration = bb_xgetlarg(t_arg, 10, 0, INT_MAX); /* We're only interested in the watchdog device .. */ if (optind < argc - 1 || argc == 1) bb_show_usage(); if (daemon(0, 1) < 0) bb_perror_msg_and_die("Failed forking watchdog daemon"); signal(SIGHUP, watchdog_shutdown); signal(SIGINT, watchdog_shutdown); fd = bb_xopen(argv[argc - 1], O_WRONLY); while (1) { /* * Make sure we clear the counter before sleeping, as the counter value * is undefined at this point -- PFM */ write(fd, "\0", 1); sleep(timer_duration); } watchdog_shutdown(0); return EXIT_SUCCESS; }
int cat_main(int argc, char **argv) { FILE *f; int retval = EXIT_SUCCESS; bb_getopt_ulflags(argc, argv, "u"); argv += optind; if (!*argv) { *--argv = "-"; } do { if ((f = bb_wfopen_input(*argv)) != NULL) { int r = bb_copyfd_eof(fileno(f), STDOUT_FILENO); bb_fclose_nonstdin(f); if (r >= 0) { continue; } } retval = EXIT_FAILURE; } while (*++argv); return retval; }
int route_main(int argc, char **argv) { unsigned long opt; int what; char *family; /* First, remap '-net' and '-host' to avoid getopt problems. */ { char **p = argv; while (*++p) { if ((strcmp(*p, "-net") == 0) || (strcmp(*p, "-host") == 0)) { p[0][0] = '#'; } } } opt = bb_getopt_ulflags(argc, argv, "A:ne", &family); if ((opt & ROUTE_OPT_A) && strcmp(family, "inet")) { #ifdef CONFIG_FEATURE_IPV6 if (strcmp(family, "inet6") == 0) { opt |= ROUTE_OPT_INET6; /* Set flag for ipv6. */ } else #endif bb_show_usage(); } argv += optind; /* No more args means display the routing table. */ if (!*argv) { int noresolve = (opt & ROUTE_OPT_n) ? 0x0fff : 0; #ifdef CONFIG_FEATURE_IPV6 if (opt & ROUTE_OPT_INET6) INET6_displayroutes(noresolve); else #endif displayroutes(noresolve, opt & ROUTE_OPT_e); bb_xferror_stdout(); bb_fflush_stdout_and_exit(EXIT_SUCCESS); } /* Check verb. At the moment, must be add, del, or delete. */ what = kw_lookup(tbl_verb, &argv); if (!what || !*argv) { /* Unknown verb or no more args. */ bb_show_usage(); } #ifdef CONFIG_FEATURE_IPV6 if (opt & ROUTE_OPT_INET6) INET6_setroute(what, argv); else #endif INET_setroute(what, argv); return EXIT_SUCCESS; }
int cpio_main(int argc, char **argv) { archive_handle_t *archive_handle; char *cpio_filename = NULL; unsigned long opt; /* Initialise */ archive_handle = init_handle(); archive_handle->src_fd = STDIN_FILENO; archive_handle->seek = seek_by_char; archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE; opt = bb_getopt_ulflags(argc, argv, "ituvF:dm", &cpio_filename); /* One of either extract or test options must be given */ if ((opt & (CPIO_OPT_TEST | CPIO_OPT_EXTRACT)) == 0) { bb_show_usage(); } if (opt & CPIO_OPT_TEST) { /* if both extract and test options are given, ignore extract option */ if (opt & CPIO_OPT_EXTRACT) { opt &= ~CPIO_OPT_EXTRACT; } archive_handle->action_header = header_list; } if (opt & CPIO_OPT_EXTRACT) { archive_handle->action_data = data_extract_all; } if (opt & CPIO_OPT_UNCONDITIONAL) { archive_handle->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL; archive_handle->flags &= ~ARCHIVE_EXTRACT_NEWER; } if (opt & CPIO_OPT_VERBOSE) { if (archive_handle->action_header == header_list) { archive_handle->action_header = header_verbose_list; } else { archive_handle->action_header = header_list; } } if (cpio_filename) { /* CPIO_OPT_FILE */ archive_handle->src_fd = bb_xopen(cpio_filename, O_RDONLY); archive_handle->seek = seek_by_jump; } if (opt & CPIO_OPT_CREATE_LEADING_DIR) { archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS; } while (optind < argc) { archive_handle->filter = filter_accept_list; llist_add_to(&(archive_handle->accept), argv[optind]); optind++; } while (get_header_cpio(archive_handle) == EXIT_SUCCESS); return(EXIT_SUCCESS); }
int start_stop_daemon_main(int argc, char **argv) { int flags; char *signame = NULL; bb_applet_long_options = ssd_long_options; flags = bb_getopt_ulflags(argc, argv, "KSba:n:s:u:x:", &startas, &cmdname, &signame, &userspec, &execname); /* Be sneaky and avoid branching */ stop = (flags & 1); start = (flags & 2); fork_before_exec = (flags & 4); if (signame) { signal_nr = bb_xgetlarg(signame, 10, 0, NSIG); } if (start == stop) bb_error_msg_and_die ("need exactly one of -S or -K"); if (!execname && !userspec) bb_error_msg_and_die ("need at least one of -x or -u"); if (!startas) startas = execname; if (start && !startas) bb_error_msg_and_die ("-S needs -x or -a"); argc -= optind; argv += optind; if (userspec && sscanf(userspec, "%d", &user_id) != 1) user_id = my_getpwnam(userspec); do_procfs(); if (stop) { do_stop(); return EXIT_SUCCESS; } if (found) { printf("%s already running.\n%d\n", execname ,found->pid); return EXIT_SUCCESS; } *--argv = startas; if (fork_before_exec) { if (daemon(0, 0) == -1) bb_perror_msg_and_die ("unable to fork"); } setsid(); execv(startas, argv); bb_perror_msg_and_die ("unable to start %s", startas); }
int start_stop_daemon_main(int argc, char **argv) { unsigned long opt; char *signame = NULL; char *startas = NULL; bb_applet_long_options = ssd_long_options; bb_opt_complementaly = "K~S:S~K"; opt = bb_getopt_ulflags(argc, argv, "KSba:n:s:u:x:", &startas, &cmdname, &signame, &userspec, &execname); /* Check one and only one context option was given */ if ((opt & 0x80000000UL) || (opt & (SSD_CTX_STOP | SSD_CTX_START)) == 0) { bb_show_usage(); } if (signame) { signal_nr = bb_xgetlarg(signame, 10, 0, NSIG); } if (!execname && !userspec) bb_error_msg_and_die ("need at least one of -x or -u"); if (!startas) startas = execname; if ((opt & SSD_CTX_START) && !startas) bb_error_msg_and_die ("-S needs -x or -a"); argc -= optind; argv += optind; if (userspec && sscanf(userspec, "%d", &user_id) != 1) user_id = my_getpwnam(userspec); do_procfs(); if (opt & SSD_CTX_STOP) { do_stop(); return EXIT_SUCCESS; } if (found) { printf("%s already running.\n%d\n", execname ,found->pid); return EXIT_SUCCESS; } *--argv = startas; if (opt & SSD_OPT_BACKGROUND) { if (daemon(0, 0) == -1) bb_perror_msg_and_die ("unable to fork"); } setsid(); execv(startas, argv); bb_perror_msg_and_die ("unable to start %s", startas); }
mode_t getopt_mk_fifo_nod(int argc, char **argv) { mode_t mode = 0666; char *smode = NULL; bb_getopt_ulflags(argc, argv, "m:", &smode); if(smode) { if (bb_parse_mode(smode, &mode)) umask(0); } return mode; }
static unsigned long chcon_parse_options(int argc, char *argv[]) { unsigned long opts; char *reference_file = NULL; #ifdef CONFIG_FEATURE_CHCON_LONG_OPTIONS bb_applet_long_options = chcon_options; #endif opts = bb_getopt_ulflags(argc, argv, "Rchf\n:u:r:t:l:v?\b", &reference_file, &user, &role, &type, &range); if (opts & OPT_CHCON_VERSION) { printf("%s - busybox %s (build: %s)\n", argv[0], BB_VER, BB_BT); exit(0); } if (opts & (OPT_CHCON_HELP | BB_GETOPT_ERROR)) bb_show_usage(); if ((opts & OPT_CHCON_QUIET) && (opts & OPT_CHCON_VERBOSE)) { fprintf(stderr, "could not specify quiet and verbose option same time\n"); bb_show_usage(); } if ((opts & OPT_CHCON_REFERENCE) && (opts & OPT_CHCON_COMPONENT_SPECIFIED)) { fprintf(stderr, "conflicting security context specifiers given\n"); bb_show_usage(); } else if (opts & OPT_CHCON_REFERENCE) { /* FIXME: lgetfilecon() should be used when '-h' is specified. */ if (getfilecon(reference_file, &specified_context) < 0) { fprintf(stderr, "getfilecon('%s'), errno=%d (%s)\n", reference_file, errno, strerror(errno)); exit(1); } } else if ((opts & OPT_CHCON_COMPONENT_SPECIFIED) == 0) { specified_context = argv[optind++]; if (!specified_context) { fprintf(stderr, "too few arguments\n"); bb_show_usage(); } } target_files = argv + optind; if (!*target_files) { fprintf(stderr, "too few arguments\n"); bb_show_usage(); } return opts; }
extern int cut_main(int argc, char **argv) { unsigned long opt; char *sopt, *sdopt; bb_opt_complementally = "b--bcf:c--bcf:f--bcf"; opt = bb_getopt_ulflags(argc, argv, optstring, &sopt, &sopt, &sopt, &sdopt); part = opt & (OPT_BYTE_FLGS|OPT_CHAR_FLGS|OPT_FIELDS_FLGS); if(part == 0) bb_error_msg_and_die("you must specify a list of bytes, characters, or fields"); if(opt & BB_GETOPT_ERROR) bb_error_msg_and_die("only one type of list may be specified"); parse_lists(sopt); if((opt & (OPT_DELIM_FLGS))) { if (strlen(sdopt) > 1) { bb_error_msg_and_die("the delimiter must be a single character"); } delim = sdopt[0]; } supress_non_delimited_lines = opt & OPT_SUPRESS_FLGS; /* non-field (char or byte) cutting has some special handling */ if (part != OPT_FIELDS_FLGS) { if (supress_non_delimited_lines) { bb_error_msg_and_die("suppressing non-delimited lines makes sense" " only when operating on fields"); } if (delim != '\t') { bb_error_msg_and_die("a delimiter may be specified only when operating on fields"); } } /* argv[(optind)..(argc-1)] should be names of file to process. If no * files were specified or '-' was specified, take input from stdin. * Otherwise, we process all the files specified. */ if (argv[optind] == NULL || (strcmp(argv[optind], "-") == 0)) { cut_file(stdin); } else { int i; FILE *file; for (i = optind; i < argc; i++) { file = bb_wfopen(argv[i], "r"); if(file) { cut_file(file); fclose(file); } } } return EXIT_SUCCESS; }
int sort_main(int argc, char **argv) { FILE *fp; char *line, **lines = NULL; int i, nlines = 0, inc; int (*compare)(const void *, const void *) = compare_ascii; int flags; bb_default_error_retval = 2; flags = bb_getopt_ulflags(argc, argv, "nru"); if (flags & 1) { compare = compare_numeric; } argv += optind; if (!*argv) { *--argv = "-"; } do { fp = xgetoptfile_sort_uniq(argv, "r"); while ((line = bb_get_chomped_line_from_file(fp)) != NULL) { lines = xrealloc(lines, sizeof(char *) * (nlines + 1)); lines[nlines++] = line; } bb_xferror(fp, *argv); bb_fclose_nonstdin(fp); } while (*++argv); /* sort it */ qsort(lines, nlines, sizeof(char *), compare); /* print it */ i = 0; --nlines; if ((inc = 1 - (flags & 2)) < 0) { /* reverse */ i = nlines; } flags &= 4; while (nlines >= 0) { if (!flags || !nlines || strcmp(lines[i+inc], lines[i])) { puts(lines[i]); } i += inc; --nlines; } bb_fflush_stdout_and_exit(EXIT_SUCCESS); }
int id_main(int argc, char **argv) { struct passwd *p; uid_t uid; gid_t gid; unsigned long flags; short status; /* Don't allow -n -r -nr -ug -rug -nug -rnug */ /* Don't allow more than one username */ bb_opt_complementally = "?1:?:u--g:g--u:r?ug:n?ug"; flags = bb_getopt_ulflags(argc, argv, "rnug"); /* This values could be overwritten later */ uid = geteuid(); gid = getegid(); if (flags & PRINT_REAL) { uid = getuid(); gid = getgid(); } if(argv[optind]) { p=getpwnam(argv[optind]); /* bb_xgetpwnam is needed because it exits on failure */ uid = bb_xgetpwnam(argv[optind]); gid = p->pw_gid; /* in this case PRINT_REAL is the same */ } if(flags & (JUST_GROUP | JUST_USER)) { /* JUST_GROUP and JUST_USER are mutually exclusive */ if(flags & NAME_NOT_NUMBER) { /* bb_getpwuid and bb_getgrgid exit on failure so puts cannot segfault */ puts((flags & JUST_USER) ? bb_getpwuid(NULL, uid, -1 ) : bb_getgrgid(NULL, gid, -1 )); } else { bb_printf("%u\n",(flags & JUST_USER) ? uid : gid); } /* exit */ bb_fflush_stdout_and_exit(EXIT_SUCCESS); } /* Print full info like GNU id */ /* bb_getpwuid doesn't exit on failure here */ status=printf_full(uid, bb_getpwuid(NULL, uid, 0), 'u'); putchar(' '); /* bb_getgrgid doesn't exit on failure here */ status|=printf_full(gid, bb_getgrgid(NULL, gid, 0), 'g'); putchar('\n'); bb_fflush_stdout_and_exit(status); }
int env_main(int argc, char** argv) { static char *cleanenv[1] = { NULL }; char **ep, *p; unsigned long opt; llist_t *unset_env = NULL; extern char **environ; bb_opt_complementally = "u::"; #if ENABLE_FEATURE_ENV_LONG_OPTIONS bb_applet_long_options = env_long_options; #endif opt = bb_getopt_ulflags(argc, argv, "+iu:", &unset_env); argv += optind; if (*argv && (argv[0][0] == '-') && !argv[0][1]) { opt |= 1; ++argv; } if(opt & 1) environ = cleanenv; else if(opt & 2) { while(unset_env) { unsetenv(unset_env->data); unset_env = unset_env->link; } } while (*argv && ((p = strchr(*argv, '=')) != NULL)) { if (putenv(*argv) < 0) { bb_perror_msg_and_die("putenv"); } ++argv; } if (*argv) { execvp(*argv, argv); /* SUSv3-mandated exit codes. */ bb_default_error_retval = (errno == ENOENT) ? 127 : 126; bb_perror_msg_and_die("%s", *argv); } for (ep = environ; *ep; ep++) { puts(*ep); } bb_fflush_stdout_and_exit(0); }
extern int env_main(int argc, char** argv) { char **ep, *p; char *cleanenv[1] = { NULL }; unsigned long opt; llist_t *unset_env; extern char **environ; bb_opt_complementaly = "u*"; bb_applet_long_options = env_long_options; opt = bb_getopt_ulflags(argc, argv, "+iu:", &unset_env); argv += optind; if (*argv && (argv[0][0] == '-') && !argv[0][1]) { opt |= 1; ++argv; } if(opt & 1) environ = cleanenv; else if(opt & 2) { while(unset_env) { unsetenv(unset_env->data); unset_env = unset_env->link; } } while (*argv && ((p = strchr(*argv, '=')) != NULL)) { if (putenv(*argv) < 0) { bb_perror_msg_and_die("putenv"); } ++argv; } if (*argv) { int er; execvp(*argv, argv); er = errno; bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */ return (er == ENOENT) ? 127 : 126; /* SUSv3-mandated exit codes. */ } for (ep = environ; *ep; ep++) { puts(*ep); } bb_fflush_stdout_and_exit(0); }
int swap_on_off_main(int argc, char **argv) { int ret; if (argc == 1) bb_show_usage(); ret = bb_getopt_ulflags(argc, argv, "a"); if (ret & DO_ALL) return do_em_all(); ret = 0; while (*++argv) ret += swap_enable_disable(*argv); return ret; }
extern int poweroff_main(int argc, char **argv) { char *delay; /* delay in seconds before rebooting */ if(bb_getopt_ulflags(argc, argv, "d:", &delay)) { sleep(atoi(delay)); } #ifndef CONFIG_INIT #ifndef RB_POWER_OFF #define RB_POWER_OFF 0x4321fedc #endif return(bb_shutdown_system(RB_POWER_OFF)); #else return kill_init(SIGUSR2); #endif }
extern int halt_main(int argc, char **argv) { char *delay; /* delay in seconds before rebooting */ if(bb_getopt_ulflags(argc, argv, "d:", &delay)) { sleep(atoi(delay)); } #ifndef CONFIG_INIT #ifndef RB_HALT_SYSTEM #define RB_HALT_SYSTEM 0xcdef0123 #endif return(bb_shutdown_system(RB_HALT_SYSTEM)); #else return kill_init(SIGUSR1); #endif }
int eject_main(int argc, char **argv) { unsigned long flags; char *device; struct mntent *m; flags = bb_getopt_ulflags(argc, argv, "t"); device = argv[optind] ? : DEFAULT_CDROM; if ((m = find_mount_point(device, bb_path_mtab_file))) { if (umount(m->mnt_dir)) { bb_error_msg_and_die("Can't umount"); } else if (ENABLE_FEATURE_MTAB_SUPPORT) { erase_mtab(m->mnt_fsname); } } if (ioctl(bb_xopen(device, (O_RDONLY | O_NONBLOCK)), (flags ? CDROMCLOSETRAY : CDROMEJECT))) { bb_perror_msg_and_die("%s", device); } return (EXIT_SUCCESS); }
/* * addgroup will take a login_name as its first parameter. * * gid * * can be customized via command-line parameters. * ________________________________________________________________________ */ int addgroup_main(int argc, char **argv) { char *group; gid_t gid = 0; /* check for min, max and missing args and exit on error */ bb_opt_complementally = "-1:?2:?"; if (bb_getopt_ulflags(argc, argv, "g:", &group)) { gid = bb_xgetlarg(group, 10, 0, LONG_MAX); } /* move past the commandline options */ argv += optind; /* need to be root */ if(geteuid()) { bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); } /* werk */ return addgroup(argv[0], gid, (argv[1]) ? argv[1] : ""); }
int chown_main(int argc, char **argv) { int flags; int retval = EXIT_SUCCESS; char *groupName; flags = bb_getopt_ulflags(argc, argv, "Rh"); if (flags & FLAG_h) chown_func = lchown; if (argc - optind < 2) { bb_show_usage(); } argv += optind; /* First, check if there is a group name here */ if ((groupName = strchr(*argv, '.')) == NULL) { groupName = strchr(*argv, ':'); } /* Check for the username and groupname */ if (groupName) { *groupName++ = '\0'; gid = get_ug_id(groupName, bb_xgetgrnam); } if (--groupName != *argv) uid = get_ug_id(*argv, bb_xgetpwnam); ++argv; /* Ok, ready to do the deed now */ do { if (! recursive_action (*argv, (flags & FLAG_R), FALSE, FALSE, fileAction, fileAction, NULL)) { retval = EXIT_FAILURE; } } while (*++argv); return retval; }
int modprobe_main(int argc, char** argv) { int rc = EXIT_SUCCESS; char *unused; bb_opt_complementally = "?V-:q-v:v-q"; main_opts = bb_getopt_ulflags(argc, argv, "acdklnqrst:vVC:", &unused, &unused); if((main_opts & (DUMP_CONF_EXIT | LIST_ALL))) return EXIT_SUCCESS; if((main_opts & (RESTRICT_DIR | CONFIG_FILE))) bb_error_msg_and_die("-t and -C not supported"); depend = build_dep ( ); if ( !depend ) bb_error_msg_and_die ( "could not parse modules.dep" ); if (remove_opt) { do { if (mod_remove ( optind < argc ? argv [optind] : NULL )) { bb_error_msg ("failed to remove module %s", argv [optind] ); rc = EXIT_FAILURE; } } while ( ++optind < argc ); } else { if (optind >= argc) bb_error_msg_and_die ( "No module or pattern provided" ); if ( mod_insert ( argv [optind], argc - optind - 1, argv + optind + 1 )) bb_error_msg_and_die ( "failed to load module %s", argv [optind] ); } /* Here would be a good place to free up memory allocated during the dependencies build. */ return rc; }
extern int reboot_main(int argc, char **argv) { char *delay; /* delay in seconds before rebooting */ if(bb_getopt_ulflags(argc, argv, "d:", &delay)) { sleep(atoi(delay)); } #ifdef CONFIG_USER_INIT /* Don't kill ourself */ signal(SIGTERM,SIG_IGN); signal(SIGHUP,SIG_IGN); setpgrp(); /* Allow Ctrl-Alt-Del to reboot system. */ init_reboot(RB_ENABLE_CAD); message(CONSOLE|LOG, "\n\rThe system is going down NOW !!\n"); sync(); /* Send signals to every process _except_ pid 1 */ message(CONSOLE|LOG, "\rSending SIGTERM to all processes.\n"); kill(-1, SIGTERM); sleep(1); sync(); message(CONSOLE|LOG, "\rSending SIGKILL to all processes.\n"); kill(-1, SIGKILL); sleep(1); sync(); init_reboot(RB_AUTOBOOT); return 0; /* Shrug */ #else return kill_init(SIGTERM); #endif }
int less_main(int argc, char **argv) { int keypress; flags = bb_getopt_ulflags(argc, argv, "EMmN~"); argc -= optind; argv += optind; files = argv; num_files = argc; if (!num_files) { if (ttyname(STDIN_FILENO) == NULL) inp_stdin = 1; else { bb_error_msg("Missing filename"); bb_show_usage(); } } strcpy(filename, (inp_stdin) ? bb_msg_standard_input : files[0]); get_terminal_width_height(0, &width, &height); data_readlines(); tcgetattr(fileno(inp), &term_orig); term_vi = term_orig; term_vi.c_lflag &= (~ICANON & ~ECHO); term_vi.c_iflag &= (~IXON & ~ICRNL); term_vi.c_oflag &= (~ONLCR); term_vi.c_cc[VMIN] = 1; term_vi.c_cc[VTIME] = 0; buffer_init(); buffer_print(); while (1) { keypress = tless_getch(); keypress_process(keypress); } }
extern int hwclock_main ( int argc, char **argv ) { unsigned long opt; int utc; #ifdef CONFIG_FEATURE_HWCLOCK_LONGOPTIONS static const struct option hwclock_long_options[] = { { "localtime", 0, 0, 'l' }, { "utc", 0, 0, 'u' }, { "show", 0, 0, 'r' }, { "hctosys", 0, 0, 's' }, { "systohc", 0, 0, 'w' }, { 0, 0, 0, 0 } }; bb_applet_long_options = hwclock_long_options; #endif bb_opt_complementally = "?:r--ws:w--rs:s--wr:l--u:u--l"; opt = bb_getopt_ulflags(argc, argv, "lursw"); /* If -u or -l wasn't given check if we are using utc */ if (opt & (HWCLOCK_OPT_UTC | HWCLOCK_OPT_LOCALTIME)) utc = opt & HWCLOCK_OPT_UTC; else utc = check_utc(); if (opt & HWCLOCK_OPT_HCTOSYS) { return to_sys_clock ( utc ); } else if (opt & HWCLOCK_OPT_SYSTOHC) { return from_sys_clock ( utc ); } else { /* default HWCLOCK_OPT_SHOW */ return show_clock ( utc ); } }
int fdformat_main(int argc,char **argv) { int ctrl; int verify; struct stat st; struct floppy_struct param; if (argc < 2) { bb_show_usage(); } verify != bb_getopt_ulflags(argc, argv, "n"); argv += optind; if (stat(*argv,&st) < 0 || access(*argv,W_OK) < 0) { bb_perror_msg_and_die(*argv); } if (!S_ISBLK(st.st_mode)) { bb_error_msg_and_die("%s: not a block device",*argv); /* do not test major - perhaps this was an USB floppy */ } ctrl = bb_xopen(*argv,O_WRONLY); if (ioctl(ctrl,FDGETPRM,(long) ¶m) < 0) { bb_perror_msg_and_die("Could not determine current format type"); } printf("%s-sided, %d tracks, %d sec/track. Total capacity %d kB.\n", (param.head == 2) ? "Double" : "Single", param.track, param.sect,param.size >> 1); format_disk(ctrl, *argv, ¶m); close(ctrl); if (verify) { verify_disk(*argv, ¶m); } return EXIT_SUCCESS; }