这篇教程C++ xmove_fd函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中xmove_fd函数的典型用法代码示例。如果您正苦于以下问题:C++ xmove_fd函数的具体用法?C++ xmove_fd怎么用?C++ xmove_fd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了xmove_fd函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: launch_helpervoid FAST_FUNC launch_helper(const char **argv){ // setup vanilla unidirectional pipes interchange int i; int pipes[4]; xpipe(pipes); xpipe(pipes + 2); // NB: handler must be installed before vfork bb_signals(0 + (1 << SIGCHLD) + (1 << SIGALRM) , signal_handler); G.helper_pid = xvfork(); i = (!G.helper_pid) * 2; // for parent:0, for child:2 close(pipes[i + 1]); // 1 or 3 - closing one write end close(pipes[2 - i]); // 2 or 0 - closing one read end xmove_fd(pipes[i], STDIN_FILENO); // 0 or 2 - using other read end xmove_fd(pipes[3 - i], STDOUT_FILENO); // 3 or 1 - other write end if (!G.helper_pid) { // child: try to execute connection helper // NB: SIGCHLD & SIGALRM revert to SIG_DFL on exec BB_EXECVP_or_die((char**)argv); } // parent // check whether child is alive //redundant:signal_handler(SIGCHLD); // child seems OK -> parent goes on atexit(kill_helper);}
开发者ID:AshutoshY,项目名称:ics4blade,代码行数:35,
示例2: eject_mainint eject_main(int argc UNUSED_PARAM, char **argv){ unsigned flags; const char *device; opt_complementary = "?1:t--T:T--t"; flags = getopt32(argv, "tT" IF_FEATURE_EJECT_SCSI("s")); device = argv[optind] ? argv[optind] : "/dev/cdrom"; /* We used to do "umount <device>" here, but it was buggy if something was mounted OVER cdrom and if cdrom is mounted many times. This works equally well (or better): #!/bin/sh umount /dev/cdrom eject /dev/cdrom */ xmove_fd(xopen_nonblocking(device), dev_fd); if (ENABLE_FEATURE_EJECT_SCSI && (flags & FLAG_SCSI)) eject_scsi(device); else eject_cdrom(flags, device); if (ENABLE_FEATURE_CLEAN_UP) close(dev_fd); return EXIT_SUCCESS;}
开发者ID:BezTebya,项目名称:busybox-w32,代码行数:31,
示例3: create_icmp_socketcreate_icmp_socket(void)#define create_icmp_socket(lsa) create_icmp_socket()#endif{ int sock;#if ENABLE_PING6 if (lsa->u.sa.sa_family == AF_INET6) sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6); else#endif sock = socket(AF_INET, SOCK_RAW, 1); /* 1 == ICMP */ if (sock < 0) { if (errno != EPERM) bb_perror_msg_and_die(bb_msg_can_not_create_raw_socket);#if defined(__linux__) || defined(__APPLE__) /* We don't have root privileges. Try SOCK_DGRAM instead. * Linux needs net.ipv4.ping_group_range for this to work. * MacOSX allows ICMP_ECHO, ICMP_TSTAMP or ICMP_MASKREQ */#if ENABLE_PING6 if (lsa->u.sa.sa_family == AF_INET6) sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_ICMPV6); else#endif sock = socket(AF_INET, SOCK_DGRAM, 1); /* 1 == ICMP */ if (sock < 0)#endif bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); } xmove_fd(sock, pingsock);}
开发者ID:qwerty1023,项目名称:wive-rtnl-firmware,代码行数:32,
示例4: reopen_logfile_to_stderrstatic void reopen_logfile_to_stderr(void){ if (G.log_filename) { int logfd = open_or_warn(G.log_filename, O_WRONLY | O_CREAT | O_APPEND); if (logfd >= 0) xmove_fd(logfd, STDERR_FILENO); }}
开发者ID:AlexShiLucky,项目名称:busybox,代码行数:8,
示例5: open_transformervoid FAST_FUNC open_transformer(int fd, const char *transform_prog)#endif{ struct fd_pair fd_pipe; int pid; xpiped_pair(fd_pipe); pid = BB_MMU ? xfork() : xvfork(); if (pid == 0) { /* Child */ close(fd_pipe.rd); /* we don't want to read from the parent */ // FIXME: error check?#if BB_MMU { transformer_aux_data_t aux; init_transformer_aux_data(&aux); aux.check_signature = check_signature; transformer(&aux, fd, fd_pipe.wr); if (ENABLE_FEATURE_CLEAN_UP) { close(fd_pipe.wr); /* send EOF */ close(fd); } /* must be _exit! bug was actually seen here */ _exit(EXIT_SUCCESS); }#else { char *argv[4]; xmove_fd(fd, 0); xmove_fd(fd_pipe.wr, 1); argv[0] = (char*)transform_prog; argv[1] = (char*)"-cf"; argv[2] = (char*)"-"; argv[3] = NULL; BB_EXECVP(transform_prog, argv); bb_perror_msg_and_die("can't execute '%s'", transform_prog); }#endif /* notreached */ } /* parent process */ close(fd_pipe.wr); /* don't want to write to the child */ xmove_fd(fd_pipe.rd, fd);}
开发者ID:KoWiki,项目名称:busybox,代码行数:45,
示例6: server_socket_cb/* Callback called by glib main loop when a client connects to ABRT's socket. */static gboolean server_socket_cb(GIOChannel *source, GIOCondition condition, gpointer ptr_unused){ kill_idle_timeout(); load_abrt_conf(); int socket = accept(g_io_channel_unix_get_fd(source), NULL, NULL); if (socket == -1) { perror_msg("accept"); goto server_socket_finitio; } log_notice("New client connected"); fflush(NULL); /* paranoia */ int pipefd[2]; xpipe(pipefd); pid_t pid = fork(); if (pid < 0) { perror_msg("fork"); close(socket); close(pipefd[0]); close(pipefd[1]); goto server_socket_finitio; } if (pid == 0) /* child */ { xdup2(socket, STDIN_FILENO); xdup2(socket, STDOUT_FILENO); close(socket); close(pipefd[0]); xmove_fd(pipefd[1], STDERR_FILENO); char *argv[3]; /* abrt-server [-s] NULL */ char **pp = argv; *pp++ = (char*)"abrt-server"; if (logmode & LOGMODE_JOURNAL) *pp++ = (char*)"-s"; *pp = NULL; execvp(argv[0], argv); perror_msg_and_die("Can't execute '%s'", argv[0]); } /* parent */ close(socket); close(pipefd[1]); add_abrt_server_proc(pid, pipefd[0]);server_socket_finitio: start_idle_timeout(); return TRUE;}
开发者ID:wlindauer,项目名称:abrt,代码行数:57,
示例7: open_to_or_warnstaticint open_to_or_warn(int to_fd, const char *filename, int flags, int mode){ int fd = open3_or_warn(filename, flags, mode); if (fd < 0) { return 1; } xmove_fd(fd, to_fd); return 0;}
开发者ID:rmyorston,项目名称:busybox-w32,代码行数:10,
示例8: cryptpw_mainint cryptpw_main(int argc UNUSED_PARAM, char **argv){ /* Supports: cryptpw -m sha256 PASS 'rounds=999999999$SALT' */ char salt[MAX_PW_SALT_LEN + sizeof("rounds=999999999$")]; char *salt_ptr; char *password; const char *opt_m, *opt_S; int fd;#if ENABLE_LONG_OPTS static const char mkpasswd_longopts[] ALIGN1 = "stdin/0" No_argument "s" "password-fd/0" Required_argument "P" "salt/0" Required_argument "S" "method/0" Required_argument "m" ; applet_long_options = mkpasswd_longopts;#endif fd = STDIN_FILENO; opt_m = CONFIG_FEATURE_DEFAULT_PASSWD_ALGO; opt_S = NULL; /* at most two non-option arguments; -P NUM */ opt_complementary = "?2"; getopt32(argv, "sP:+S:m:a:", &fd, &opt_S, &opt_m, &opt_m); argv += optind; /* have no idea how to handle -s... */ if (argv[0] && !opt_S) opt_S = argv[1]; salt_ptr = crypt_make_pw_salt(salt, opt_m); if (opt_S) /* put user's data after the "$N$" prefix */ safe_strncpy(salt_ptr, opt_S, sizeof(salt) - (sizeof("$N$")-1)); xmove_fd(fd, STDIN_FILENO); password = argv[0]; if (!password) { /* Only mkpasswd, and only from tty, prompts. * Otherwise it is a plain read. */ password = (ENABLE_MKPASSWD && isatty(STDIN_FILENO) && applet_name[0] == 'm') ? bb_ask_stdin("Password: ") : xmalloc_fgetline(stdin) ; /* may still be NULL on EOF/error */ } if (password) puts(pw_encrypt(password, salt, 1)); return EXIT_SUCCESS;}
开发者ID:farrellpeng,项目名称:MX283Linux,代码行数:54,
示例9: start_loggingstatic void start_logging(void){ /* Open stdin to /dev/null */ xmove_fd(xopen("/dev/null", O_RDWR), STDIN_FILENO); /* We must not leave fds 0,1,2 closed. * Otherwise fprintf(stderr) dumps messages into random fds, etc. */ xdup2(STDIN_FILENO, STDOUT_FILENO); xdup2(STDIN_FILENO, STDERR_FILENO); logmode = LOGMODE_JOURNAL; putenv((char*)"ABRT_SYSLOG=1");}
开发者ID:wlindauer,项目名称:abrt,代码行数:11,
示例10: launch_helpervoid FAST_FUNC launch_helper(const char **argv){ // setup vanilla unidirectional pipes interchange int i; int pipes[4]; xpipe(pipes); xpipe(pipes + 2); // NB: handler must be installed before vfork bb_signals(0 + (1 << SIGCHLD) + (1 << SIGALRM) , signal_handler); G.helper_pid = xvfork(); i = (!G.helper_pid) * 2; // for parent:0, for child:2 close(pipes[i + 1]); // 1 or 3 - closing one write end close(pipes[2 - i]); // 2 or 0 - closing one read end xmove_fd(pipes[i], STDIN_FILENO); // 0 or 2 - using other read end xmove_fd(pipes[3 - i], STDOUT_FILENO); // 3 or 1 - using other write end // End result: // parent stdout [3] -> child stdin [2] // child stdout [1] -> parent stdin [0] if (!G.helper_pid) { // child // if parent dies, get SIGTERM prctl(PR_SET_PDEATHSIG, SIGTERM, 0, 0, 0); // try to execute connection helper // NB: SIGCHLD & SIGALRM revert to SIG_DFL on exec BB_EXECVP_or_die((char**)argv); } // parent goes on}
开发者ID:rehsack,项目名称:busybox,代码行数:37,
示例11: open_file_and_read_linesstatic void open_file_and_read_lines(void){ if (filename) { xmove_fd(xopen(filename, O_RDONLY), STDIN_FILENO); } else { /* "less" with no arguments in argv[] */ /* For status line only */ filename = xstrdup(bb_msg_standard_input); } readpos = 0; readeof = 0; last_line_pos = 0; terminated = 1; read_lines();}
开发者ID:ack3000,项目名称:busybox,代码行数:15,
示例12: cryptpw_mainint cryptpw_main(int argc UNUSED_PARAM, char **argv){ char salt[MAX_PW_SALT_LEN]; char *salt_ptr; const char *opt_m, *opt_S; int fd;#if ENABLE_LONG_OPTS static const char mkpasswd_longopts[] ALIGN1 = "stdin/0" No_argument "s" "password-fd/0" Required_argument "P" "salt/0" Required_argument "S" "method/0" Required_argument "m" ; applet_long_options = mkpasswd_longopts;#endif fd = STDIN_FILENO; opt_m = "d"; opt_S = NULL; /* at most two non-option arguments; -P NUM */ opt_complementary = "?2:P+"; getopt32(argv, "sP:S:m:a:", &fd, &opt_S, &opt_m, &opt_m); argv += optind; /* have no idea how to handle -s... */ if (argv[0] && !opt_S) opt_S = argv[1]; salt_ptr = crypt_make_pw_salt(salt, opt_m); if (opt_S) safe_strncpy(salt_ptr, opt_S, sizeof(salt) - (sizeof("$N$")-1)); xmove_fd(fd, STDIN_FILENO); puts(pw_encrypt( argv[0] ? argv[0] : ( /* Only mkpasswd, and only from tty, prompts. * Otherwise it is a plain read. */ (isatty(STDIN_FILENO) && applet_name[0] == 'm') ? bb_ask_stdin("Password: ") : xmalloc_fgetline(stdin) ), salt, 1)); return EXIT_SUCCESS;}
开发者ID:AshutoshY,项目名称:ics4blade,代码行数:47,
示例13: watchdog_mainint watchdog_main(int argc, char **argv){ unsigned opts; unsigned timer_duration = 30000; /* Userspace timer duration, in milliseconds */ char *t_arg; opt_complementary = "=1"; /* must have 1 argument */ opts = getopt32(argv, "Ft:", &t_arg); if (opts & OPT_TIMER) { static const struct suffix_mult suffixes[] = { { "ms", 1 }, { "", 1000 }, { } }; timer_duration = xatou_sfx(t_arg, suffixes); } if (!(opts & OPT_FOREGROUND)) { bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv); } bb_signals(BB_FATAL_SIGS, watchdog_shutdown); /* Use known fd # - avoid needing global 'int fd' */ xmove_fd(xopen(argv[argc - 1], O_WRONLY), 3);// TODO?// if (!(opts & OPT_TIMER)) {// if (ioctl(fd, WDIOC_GETTIMEOUT, &timer_duration) == 0)// timer_duration *= 500;// else// timer_duration = 30000;// } while (1) { /* * Make sure we clear the counter before sleeping, as the counter value * is undefined at this point -- PFM */ write(3, "", 1); /* write zero byte */ usleep(timer_duration * 1000L); } return EXIT_SUCCESS; /* - not reached, but gcc 4.2.1 is too dumb! */}
开发者ID:aYosukeAkatsuka,项目名称:edimax-br-6528n,代码行数:45,
示例14: rpm2cpio_mainint rpm2cpio_main(int argc UNUSED_PARAM, char **argv){ struct rpm_lead lead; unsigned pos; if (argv[1]) { xmove_fd(xopen(argv[1], O_RDONLY), rpm_fd); } xread(rpm_fd, &lead, sizeof(lead)); /* Just check the magic, the rest is irrelevant */ if (lead.magic != htonl(RPM_LEAD_MAGIC)) { bb_error_msg_and_die("invalid RPM magic"); } /* Skip the signature header, align to 8 bytes */ pos = skip_header(); seek_by_jump(rpm_fd, (-(int)pos) & 7); /* Skip the main header */ skip_header(); //if (SEAMLESS_COMPRESSION) // /* We need to know whether child (gzip/bzip/etc) exits abnormally */ // signal(SIGCHLD, check_errors_in_children); /* This works, but doesn't report uncompress errors (they happen in child) */ setup_unzip_on_fd(rpm_fd, /*fail_if_not_compressed:*/ 1); if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0) bb_error_msg_and_die("error unpacking"); if (ENABLE_FEATURE_CLEAN_UP) { close(rpm_fd); } if (SEAMLESS_COMPRESSION) { check_errors_in_children(0); return bb_got_signal; } return EXIT_SUCCESS;}
开发者ID:AlexShiLucky,项目名称:busybox,代码行数:41,
示例15: crondlogstatic void crondlog(const char *ctl, ...){ va_list va; int level = (ctl[0] & 0x1f); va_start(va, ctl); if (level >= (int)LogLevel) { /* Debug mode: all to (non-redirected) stderr, */ /* Syslog mode: all to syslog (logmode = LOGMODE_SYSLOG), */ if (!DebugOpt && LogFile) { /* Otherwise (log to file): we reopen log file at every write: */ int logfd = open3_or_warn(LogFile, O_WRONLY | O_CREAT | O_APPEND, 0600); if (logfd >= 0) xmove_fd(logfd, STDERR_FILENO); }// TODO: ERR -> error, WARN -> warning, LVL -> info bb_verror_msg(ctl + 1, va, /* strerr: */ NULL); } va_end(va); if (ctl[0] & 0x80) exit(20);}
开发者ID:aYosukeAkatsuka,项目名称:edimax-br-6528n,代码行数:22,
示例16: console_init_3200int console_init_3200(){ struct serial_struct sr; char *s; printf("console init/n"); // tmp test s = getenv("CONSOLE"); if (!s) s = getenv("console"); if (s) { int fd = open(s, O_RDWR | O_NONBLOCK | O_NOCTTY); if (fd >= 0) { dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); xmove_fd(fd, STDERR_FILENO); } messageD(L_LOG, "console='%s'", s); } else { /* Make sure fd 0,1,2 are not closed * (so that they won't be used by future opens) */ bb_sanitize_stdio(); } s = getenv("TERM"); if (ioctl(STDIN_FILENO, TIOCGSERIAL, &sr) == 0) { /* Force the TERM setting to vt102 for serial console * if TERM is set to linux (the default) */ if (!s || strcmp(s, "linux") == 0) putenv((char*)"TERM=vt102"); if (!ENABLE_FEATURE_INIT_SYSLOG) log_console = NULL; } else if (!s) putenv((char*)"TERM=linux"); return 0;}
开发者ID:GunioRobot,项目名称:rtn56u,代码行数:37,
示例17: fork_jobstatic pid_tfork_job(const char *user, int mailFd, CronLine *line, bool run_sendmail){ struct passwd *pas; const char *shell, *prog; smallint sv_logmode; pid_t pid; /* prepare things before vfork */ pas = getpwnam(user); if (!pas) { bb_error_msg("can't get uid for %s", user); goto err; } shell = line->cl_shell ? line->cl_shell : DEFAULT_SHELL; prog = run_sendmail ? SENDMAIL : shell; set_env_vars(pas, shell); sv_logmode = logmode; pid = vfork(); if (pid == 0) { /* CHILD */ /* initgroups, setgid, setuid, and chdir to home or CRON_DIR */ change_user(pas); log5("child running %s", prog); if (mailFd >= 0) { xmove_fd(mailFd, run_sendmail ? 0 : 1); dup2(1, 2); } /* crond 3.0pl1-100 puts tasks in separate process groups */ bb_setpgrp(); if (!run_sendmail) execlp(prog, prog, "-c", line->cl_cmd, (char *) NULL); else execlp(prog, prog, SENDMAIL_ARGS, (char *) NULL); /* * I want this error message on stderr too, * even if other messages go only to syslog: */ logmode |= LOGMODE_STDIO; bb_error_msg_and_die("can't execute '%s' for user %s", prog, user); } logmode = sv_logmode; if (pid < 0) { bb_perror_msg("vfork"); err: pid = 0; } /* else: PARENT, FORK SUCCESS */ /* * Close the mail file descriptor.. we can't just leave it open in * a structure, closing it later, because we might run out of descriptors */ if (mailFd >= 0) { close(mailFd); } return pid;}
开发者ID:AlexShiLucky,项目名称:busybox,代码行数:61,
示例18: zcip_mainint zcip_main(int argc UNUSED_PARAM, char **argv){ int state; char *r_opt; unsigned opts; // ugly trick, but I want these zeroed in one go struct { const struct in_addr null_ip; const struct ether_addr null_addr; struct in_addr ip; struct ifreq ifr; int timeout_ms; /* must be signed */ unsigned conflicts; unsigned nprobes; unsigned nclaims; int ready; } L;#define null_ip (L.null_ip )#define null_addr (L.null_addr )#define ip (L.ip )#define ifr (L.ifr )#define timeout_ms (L.timeout_ms)#define conflicts (L.conflicts )#define nprobes (L.nprobes )#define nclaims (L.nclaims )#define ready (L.ready ) memset(&L, 0, sizeof(L)); INIT_G();#define FOREGROUND (opts & 1)#define QUIT (opts & 2) // parse commandline: prog [options] ifname script // exactly 2 args; -v accumulates and implies -f opt_complementary = "=2:vv:vf"; opts = getopt32(argv, "fqr:p:v", &r_opt, &pidfile, &verbose);#if !BB_MMU // on NOMMU reexec early (or else we will rerun things twice) if (!FOREGROUND) bb_daemonize_or_rexec(0 /*was: DAEMON_CHDIR_ROOT*/, argv);#endif // open an ARP socket // (need to do it before openlog to prevent openlog from taking // fd 3 (sock_fd==3)) xmove_fd(xsocket(AF_PACKET, SOCK_PACKET, htons(ETH_P_ARP)), sock_fd); if (!FOREGROUND) { // do it before all bb_xx_msg calls openlog(applet_name, 0, LOG_DAEMON); logmode |= LOGMODE_SYSLOG; } if (opts & 4) { // -r n.n.n.n if (inet_aton(r_opt, &ip) == 0 || (ntohl(ip.s_addr) & IN_CLASSB_NET) != LINKLOCAL_ADDR ) { bb_error_msg_and_die("invalid link address"); } } argv += optind - 1; /* Now: argv[0]:junk argv[1]:intf argv[2]:script argv[3]:NULL */ /* We need to make space for script argument: */ argv[0] = argv[1]; argv[1] = argv[2]; /* Now: argv[0]:intf argv[1]:script argv[2]:junk argv[3]:NULL */#define argv_intf (argv[0]) xsetenv("interface", argv_intf); // initialize the interface (modprobe, ifup, etc) if (run(argv, "init", NULL)) return EXIT_FAILURE; // initialize saddr // saddr is: { u16 sa_family; u8 sa_data[14]; } //memset(&saddr, 0, sizeof(saddr)); //TODO: are we leaving sa_family == 0 (AF_UNSPEC)?! safe_strncpy(saddr.sa_data, argv_intf, sizeof(saddr.sa_data)); // bind to the interface's ARP socket xbind(sock_fd, &saddr, sizeof(saddr)); // get the interface's ethernet address //memset(&ifr, 0, sizeof(ifr)); strncpy_IFNAMSIZ(ifr.ifr_name, argv_intf); xioctl(sock_fd, SIOCGIFHWADDR, &ifr); memcpy(ð_addr, &ifr.ifr_hwaddr.sa_data, ETH_ALEN); // start with some stable ip address, either a function of // the hardware address or else the last address we used. // we are taking low-order four bytes, as top-order ones // aren't random enough. // NOTE: the sequence of addresses we try changes only // depending on when we detect conflicts. { uint32_t t; move_from_unaligned32(t, ((char *)ð_addr + 2)); srand(t); } if (ip.s_addr == 0)//.........这里部分代码省略.........
开发者ID:sdg7,项目名称:wl500g,代码行数:101,
示例19: fork_execv_on_steroids/* Returns pid */pid_t fork_execv_on_steroids(int flags, char **argv, int *pipefds, char **env_vec, const char *dir, uid_t uid){ pid_t child; /* Reminder: [0] is read end, [1] is write end */ int pipe_to_child[2]; int pipe_fm_child[2]; /* Sanitize flags */ if (!pipefds) flags &= ~(EXECFLG_INPUT | EXECFLG_OUTPUT); if (flags & EXECFLG_INPUT) xpipe(pipe_to_child); if (flags & EXECFLG_OUTPUT) xpipe(pipe_fm_child); fflush(NULL); child = fork(); if (child == -1) { perror_msg_and_die("fork"); } if (child == 0) { /* Child */ if (dir) xchdir(dir); if (flags & EXECFLG_SETGUID) { struct passwd* pw = getpwuid(uid); gid_t gid = pw ? pw->pw_gid : uid; setgroups(1, &gid); xsetregid(gid, gid); xsetreuid(uid, uid); } if (env_vec) { /* Note: we use the glibc extension that putenv("var") * *unsets* $var if "var" string has no '=' */ while (*env_vec) putenv(*env_vec++); } /* Play with stdio descriptors */ if (flags & EXECFLG_INPUT) { xmove_fd(pipe_to_child[0], STDIN_FILENO); close(pipe_to_child[1]); } else if (flags & EXECFLG_INPUT_NUL) { xmove_fd(xopen("/dev/null", O_RDWR), STDIN_FILENO); } if (flags & EXECFLG_OUTPUT) { xmove_fd(pipe_fm_child[1], STDOUT_FILENO); close(pipe_fm_child[0]); } else if (flags & EXECFLG_OUTPUT_NUL) { xmove_fd(xopen("/dev/null", O_RDWR), STDOUT_FILENO); } /* This should be done BEFORE stderr redirect */ VERB1 { char *r = concat_str_vector(argv); log("Executing: %s", r); free(r); } if (flags & EXECFLG_ERR2OUT) { /* Want parent to see errors in the same stream */ xdup2(STDOUT_FILENO, STDERR_FILENO); } else if (flags & EXECFLG_ERR_NUL) { xmove_fd(xopen("/dev/null", O_RDWR), STDERR_FILENO); } if (flags & EXECFLG_SETSID) setsid(); execvp(argv[0], argv); if (!(flags & EXECFLG_QUIET)) perror_msg("Can't execute '%s'", argv[0]); exit(127); /* shell uses this exit code in this case */ } if (flags & EXECFLG_INPUT) { close(pipe_to_child[0]); pipefds[1] = pipe_to_child[1]; } if (flags & EXECFLG_OUTPUT) { close(pipe_fm_child[1]); pipefds[0] = pipe_fm_child[0]; } return child;}
开发者ID:rplnt,项目名称:abrt,代码行数:96,
示例20: add_remove_shell_mainint add_remove_shell_main(int argc UNUSED_PARAM, char **argv){ FILE *orig_fp; char *orig_fn; char *new_fn; struct stat sb; sb.st_mode = 0666; argv++; orig_fn = xmalloc_follow_symlinks(SHELLS_FILE); if (!orig_fn) return EXIT_FAILURE; orig_fp = fopen_for_read(orig_fn); if (orig_fp) xfstat(fileno(orig_fp), &sb, orig_fn); new_fn = xasprintf("%s.tmp", orig_fn); /* * O_TRUNC or O_EXCL? At the first glance, O_EXCL looks better, * since it prevents races. But: (1) it requires a retry loop, * (2) if /etc/shells.tmp is *stale*, then retry loop * with O_EXCL will never succeed - it should have a timeout, * after which it should revert to O_TRUNC. * For now, I settle for O_TRUNC instead. */ xmove_fd(xopen3(new_fn, O_WRONLY | O_CREAT | O_TRUNC, sb.st_mode), STDOUT_FILENO); /* TODO? xfchown(STDOUT_FILENO, sb.st_uid, sb.st_gid); */ if (orig_fp) { /* Copy old file, possibly skipping removed shell names */ char *line; while ((line = xmalloc_fgetline(orig_fp)) != NULL) { char **cpp = argv; while (*cpp) { if (*cpp != dont_add && strcmp(*cpp, line) == 0) { /* Old file has this shell name */ if (REMOVE_SHELL) { /* we are remove-shell */ /* delete this name by not copying it */ goto next_line; } /* we are add-shell */ /* mark this name as "do not add" */ *cpp = dont_add; } cpp++; } /* copy shell name from old to new file */ puts(line); next_line: free(line); } if (ENABLE_FEATURE_CLEAN_UP) fclose(orig_fp); } if (ADD_SHELL) { char **cpp = argv; while (*cpp) { if (*cpp != dont_add) puts(*cpp); cpp++; } } /* Ensure we wrote out everything */ if (fclose(stdout) != 0) { xunlink(new_fn); bb_perror_msg_and_die("%s: write error", new_fn); } /* Small hole: if rename fails, /etc/shells.tmp is not removed */ xrename(new_fn, orig_fn); if (ENABLE_FEATURE_CLEAN_UP) { free(orig_fn); free(new_fn); } return EXIT_SUCCESS;}
开发者ID:android-ide,项目名称:busybox,代码行数:85,
示例21: writeTarFilestatic int writeTarFile(const int tar_fd, const int verboseFlag, const unsigned long dereferenceFlag, const llist_t *include, const llist_t *exclude, const int gzip){ pid_t gzipPid = 0; int errorFlag = FALSE; struct TarBallInfo tbInfo; tbInfo.hlInfoHead = NULL; fchmod(tar_fd, 0644); tbInfo.tarFd = tar_fd; tbInfo.verboseFlag = verboseFlag; /* Store the stat info for the tarball's file, so * can avoid including the tarball into itself.... */ if (fstat(tbInfo.tarFd, &tbInfo.statBuf) < 0) bb_perror_msg_and_die("cannot stat tar file");#if ENABLE_FEATURE_TAR_GZIP || ENABLE_FEATURE_TAR_BZIP2 if (gzip) {#if ENABLE_FEATURE_TAR_GZIP && ENABLE_FEATURE_TAR_BZIP2 const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";#elif ENABLE_FEATURE_TAR_GZIP const char *zip_exec = "gzip";#else /* only ENABLE_FEATURE_TAR_BZIP2 */ const char *zip_exec = "bzip2";#endif // On Linux, vfork never unpauses parent early, although standard // allows for that. Do we want to waste bytes checking for it?#define WAIT_FOR_CHILD 0 volatile int vfork_exec_errno = 0;#if WAIT_FOR_CHILD struct fd_pair gzipStatusPipe;#endif struct fd_pair gzipDataPipe; xpiped_pair(gzipDataPipe);#if WAIT_FOR_CHILD xpiped_pair(gzipStatusPipe);#endif signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */#if defined(__GNUC__) && __GNUC__ /* Avoid vfork clobbering */ (void) &include; (void) &errorFlag; (void) &zip_exec;#endif gzipPid = vfork(); if (gzipPid < 0) bb_perror_msg_and_die("vfork gzip"); if (gzipPid == 0) { /* child */ /* NB: close _first_, then move fds! */ close(gzipDataPipe.wr);#if WAIT_FOR_CHILD close(gzipStatusPipe.rd); /* gzipStatusPipe.wr will close only on exec - * parent waits for this close to happen */ fcntl(gzipStatusPipe.wr, F_SETFD, FD_CLOEXEC);#endif xmove_fd(gzipDataPipe.rd, 0); xmove_fd(tbInfo.tarFd, 1); /* exec gzip/bzip2 program/applet */ BB_EXECLP(zip_exec, zip_exec, "-f", NULL); vfork_exec_errno = errno; _exit(1); } /* parent */ xmove_fd(gzipDataPipe.wr, tbInfo.tarFd); close(gzipDataPipe.rd);#if WAIT_FOR_CHILD close(gzipStatusPipe.wr); while (1) { char buf; int n; /* Wait until child execs (or fails to) */ n = full_read(gzipStatusPipe.rd, &buf, 1); if (n < 0 /* && errno == EAGAIN */) continue; /* try it again */ } close(gzipStatusPipe.rd);#endif if (vfork_exec_errno) { errno = vfork_exec_errno; bb_perror_msg_and_die("cannot exec %s", zip_exec); } }#endif tbInfo.excludeList = exclude; /* Read the directory/files and iterate over them one at a time */ while (include) {//.........这里部分代码省略.........
开发者ID:ph4r05,项目名称:boinc,代码行数:101,
示例22: sendmail_main//.........这里部分代码省略......... // Wait for initial server message. // If helper (such as openssl) invokes STARTTLS, the initial 220 // is swallowed by helper (and not repeated after TLS is initiated). // We will send NOOP cmd to server and check the response. // We should get 220+250 on plain connection, 250 on STARTTLSed session. // // The problem here is some servers delay initial 220 message, // and consider client to be a spammer if it starts sending cmds // before 220 reached it. The code below is unsafe in this regard: // in non-STARTTLSed case, we potentially send NOOP before 220 // is sent by server. // Ideas? (--delay SECS opt? --assume-starttls-helper opt?) code = smtp_check("NOOP", -1); if (code == 220) // we got 220 - this is not STARTTLSed connection, // eat 250 response to our NOOP smtp_check(NULL, 250); else if (code != 250) bb_error_msg_and_die("SMTP init failed"); } else { // vanilla connection int fd; // host[:port] not explicitly specified? -> use $SMTPHOST // no $SMTPHOST? -> use localhost if (!(opts & OPT_S)) { opt_connect = getenv("SMTPHOST"); if (!opt_connect) opt_connect = (char *)"127.0.0.1"; } // do connect fd = create_and_connect_stream_or_die(opt_connect, 25); // and make ourselves a simple IO filter xmove_fd(fd, STDIN_FILENO); xdup2(STDIN_FILENO, STDOUT_FILENO); // Wait for initial server 220 message smtp_check(NULL, 220); } // we should start with modern EHLO if (250 != smtp_checkp("EHLO %s", host, -1)) smtp_checkp("HELO %s", host, 250); // perform authentication if (opts & OPT_a) { smtp_check("AUTH LOGIN", 334); // we must read credentials unless they are given via -a[up] options if (!G.user || !G.pass) get_cred_or_die(4); encode_base64(NULL, G.user, NULL); smtp_check("", 334); encode_base64(NULL, G.pass, NULL); smtp_check("", 235); } // set sender // N.B. we have here a very loosely defined algorythm // since sendmail historically offers no means to specify secrets on cmdline. // 1) server can require no authentication -> // we must just provide a (possibly fake) reply address. // 2) server can require AUTH -> // we must provide valid username and password along with a (possibly fake) reply address. // For the sake of security username and password are to be read either from console or from a secured file. // Since reading from console may defeat usability, the solution is either to read from a predefined // file descriptor (e.g. 4), or again from a secured file.
开发者ID:Crobisaur,项目名称:busybox,代码行数:67,
示例23: vfork_compressor/* Don't inline: vfork scares gcc and pessimizes code */static void NOINLINE vfork_compressor(int tar_fd, int gzip){ pid_t gzipPid;#if ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2 const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";#elif ENABLE_FEATURE_SEAMLESS_GZ const char *zip_exec = "gzip";#else /* only ENABLE_FEATURE_SEAMLESS_BZ2 */ const char *zip_exec = "bzip2";#endif // On Linux, vfork never unpauses parent early, although standard // allows for that. Do we want to waste bytes checking for it?#define WAIT_FOR_CHILD 0 volatile int vfork_exec_errno = 0; struct fd_pair gzipDataPipe;#if WAIT_FOR_CHILD struct fd_pair gzipStatusPipe; xpiped_pair(gzipStatusPipe);#endif xpiped_pair(gzipDataPipe); signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */#if defined(__GNUC__) && __GNUC__ /* Avoid vfork clobbering */ (void) &zip_exec;#endif gzipPid = vfork(); if (gzipPid < 0) bb_perror_msg_and_die("vfork"); if (gzipPid == 0) { /* child */ /* NB: close _first_, then move fds! */ close(gzipDataPipe.wr);#if WAIT_FOR_CHILD close(gzipStatusPipe.rd); /* gzipStatusPipe.wr will close only on exec - * parent waits for this close to happen */ fcntl(gzipStatusPipe.wr, F_SETFD, FD_CLOEXEC);#endif xmove_fd(gzipDataPipe.rd, 0); xmove_fd(tar_fd, 1); /* exec gzip/bzip2 program/applet */ BB_EXECLP(zip_exec, zip_exec, "-f", NULL); vfork_exec_errno = errno; _exit(EXIT_FAILURE); } /* parent */ xmove_fd(gzipDataPipe.wr, tar_fd); close(gzipDataPipe.rd);#if WAIT_FOR_CHILD close(gzipStatusPipe.wr); while (1) { char buf; int n; /* Wait until child execs (or fails to) */ n = full_read(gzipStatusPipe.rd, &buf, 1); if (n < 0 /* && errno == EAGAIN */) continue; /* try it again */ } close(gzipStatusPipe.rd);#endif if (vfork_exec_errno) { errno = vfork_exec_errno; bb_perror_msg_and_die("can't execute '%s'", zip_exec); }}
开发者ID:Cheezzolo123,项目名称:MonteDroid,代码行数:72,
示例24: vlock_mainint vlock_main(int argc UNUSED_PARAM, char **argv){#ifdef __linux__ struct vt_mode vtm; struct vt_mode ovtm;#endif struct termios term; struct termios oterm; struct passwd *pw; pw = xgetpwuid(getuid()); opt_complementary = "=0"; /* no params! */ getopt32(argv, "a"); /* Ignore some signals so that we don't get killed by them */ bb_signals(0 + (1 << SIGTSTP) + (1 << SIGTTIN) + (1 << SIGTTOU) + (1 << SIGHUP ) + (1 << SIGCHLD) /* paranoia :) */ + (1 << SIGQUIT) + (1 << SIGINT ) , SIG_IGN);#ifdef __linux__ /* We will use SIGUSRx for console switch control: */ /* 1: set handlers */ signal_SA_RESTART_empty_mask(SIGUSR1, release_vt); signal_SA_RESTART_empty_mask(SIGUSR2, acquire_vt); /* 2: unmask them */ sig_unblock(SIGUSR1); sig_unblock(SIGUSR2);#endif /* Revert stdin/out to our controlling tty * (or die if we have none) */ xmove_fd(xopen(CURRENT_TTY, O_RDWR), STDIN_FILENO); xdup2(STDIN_FILENO, STDOUT_FILENO);#ifdef __linux__ xioctl(STDIN_FILENO, VT_GETMODE, &vtm); ovtm = vtm; /* "console switches are controlled by us, not kernel!" */ vtm.mode = VT_PROCESS; vtm.relsig = SIGUSR1; vtm.acqsig = SIGUSR2; ioctl(STDIN_FILENO, VT_SETMODE, &vtm);#endif//TODO: use set_termios_to_raw() tcgetattr(STDIN_FILENO, &oterm); term = oterm; term.c_iflag |= IGNBRK; /* ignore serial break (why? VTs don't have breaks, right?) */ term.c_iflag &= ~BRKINT; /* redundant? "dont translate break to SIGINT" */ term.c_lflag &= ~(ISIG | ECHO | ECHOCTL); /* ignore ^C ^Z, echo off */ tcsetattr_stdin_TCSANOW(&term); while (1) { printf("Virtual console%s locked by %s./n", /* "s" if -a, else "": */ "s" + !option_mask32, pw->pw_name ); if (ask_and_check_password(pw) > 0) { break; } bb_do_delay(LOGIN_FAIL_DELAY); puts("Incorrect password"); }#ifdef __linux__ ioctl(STDIN_FILENO, VT_SETMODE, &ovtm);#endif tcsetattr_stdin_TCSANOW(&oterm); fflush_stdout_and_exit(EXIT_SUCCESS);}
开发者ID:android-ide,项目名称:busybox,代码行数:76,
示例25: stty_main//.........这里部分代码省略......... case param_ispeed: /* called for the side effect of xfunc death only */ set_speed_or_die(input_speed, argnext, &mode); break; case param_ospeed: /* called for the side effect of xfunc death only */ set_speed_or_die(output_speed, argnext, &mode); break; default: if (recover_mode(arg, &mode) == 1) break; if (tty_value_to_baud(xatou(arg)) != (speed_t) -1) break; invalid_argument: bb_error_msg_and_die("invalid argument '%s'", arg); } stty_state &= ~STTY_noargs; } /* Specifying both -a and -g is an error */ if ((stty_state & (STTY_verbose_output | STTY_recoverable_output)) == (STTY_verbose_output | STTY_recoverable_output) ) { bb_error_msg_and_die("-a and -g are mutually exclusive"); } /* Specifying -a or -g with non-options is an error */ if ((stty_state & (STTY_verbose_output | STTY_recoverable_output)) && !(stty_state & STTY_noargs) ) { bb_error_msg_and_die("modes may not be set when -a or -g is used"); } /* Now it is safe to start doing things */ if (file_name) { G.device_name = file_name; xmove_fd(xopen_nonblocking(G.device_name), STDIN_FILENO); ndelay_off(STDIN_FILENO); } /* Initialize to all zeroes so there is no risk memcmp will report a spurious difference in an uninitialized portion of the structure */ memset(&mode, 0, sizeof(mode)); if (tcgetattr(STDIN_FILENO, &mode)) perror_on_device_and_die("%s"); if (stty_state & (STTY_verbose_output | STTY_recoverable_output | STTY_noargs)) { G.max_col = get_terminal_width(STDOUT_FILENO); output_func(&mode, display_all); return EXIT_SUCCESS; } /* Second pass: perform actions */ k = 0; while (argv[++k]) { const struct mode_info *mp; const struct control_info *cp; const char *arg = argv[k]; const char *argnext = argv[k+1]; int param; if (arg[0] == '-') { mp = find_mode(arg+1); if (mp) { set_mode(mp, 1 /* reversed */, &mode); stty_state |= STTY_require_set_attr; } /* It is an option - already parsed. Skip it */ continue;
开发者ID:Crobisaur,项目名称:busybox,代码行数:67,
示例26: ifplugd_mainint ifplugd_main(int argc UNUSED_PARAM, char **argv){ int iface_status; int delay_time; const char *iface_status_str; struct pollfd netlink_pollfd[1]; unsigned opts; const char *api_mode_found;#if ENABLE_FEATURE_PIDFILE char *pidfile_name; pid_t pid_from_pidfile;#endif INIT_G(); opt_complementary = "t+:u+:d+"; opts = getopt32(argv, OPTION_STR, &G.iface, &G.script_name, &G.poll_time, &G.delay_up, &G.delay_down, &G.api_mode, &G.extra_arg); G.poll_time *= 1000; applet_name = xasprintf("ifplugd(%s)", G.iface);#if ENABLE_FEATURE_PIDFILE pidfile_name = xasprintf(CONFIG_PID_FILE_PATH "/ifplugd.%s.pid", G.iface); pid_from_pidfile = read_pid(pidfile_name); if (opts & FLAG_KILL) { if (pid_from_pidfile > 0) /* Upstream tool use SIGINT for -k */ kill(pid_from_pidfile, SIGINT); return EXIT_SUCCESS; } if (pid_from_pidfile > 0 && kill(pid_from_pidfile, 0) == 0) bb_error_msg_and_die("daemon already running");#endif api_mode_found = strchr(api_modes, G.api_mode[0]); if (!api_mode_found) bb_error_msg_and_die("unknown API mode '%s'", G.api_mode); G.api_method_num = api_mode_found - api_modes; if (!(opts & FLAG_NO_DAEMON)) bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv); xmove_fd(xsocket(AF_INET, SOCK_DGRAM, 0), ioctl_fd); if (opts & FLAG_MONITOR) { struct sockaddr_nl addr; int fd = xsocket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); memset(&addr, 0, sizeof(addr)); addr.nl_family = AF_NETLINK; addr.nl_groups = RTMGRP_LINK; addr.nl_pid = getpid(); xbind(fd, (struct sockaddr*)&addr, sizeof(addr)); xmove_fd(fd, netlink_fd); } write_pidfile(pidfile_name); /* this can't be moved before socket creation */ if (!(opts & FLAG_NO_SYSLOG)) { openlog(applet_name, 0, LOG_DAEMON); logmode |= LOGMODE_SYSLOG; } bb_signals(0 | (1 << SIGINT ) | (1 << SIGTERM) | (1 << SIGQUIT) | (1 << SIGHUP ) /* why we ignore it? */ /* | (1 << SIGCHLD) - run_script does not use it anymore */ , record_signo); bb_error_msg("started: %s", bb_banner); if (opts & FLAG_MONITOR) { struct ifreq ifrequest; set_ifreq_to_ifname(&ifrequest); G.iface_exists = (network_ioctl(SIOCGIFINDEX, &ifrequest, NULL) == 0); } if (G.iface_exists) maybe_up_new_iface(); iface_status = detect_link(); if (iface_status == IFSTATUS_ERR) goto exiting; iface_status_str = strstatus(iface_status); if (opts & FLAG_MONITOR) { bb_error_msg("interface %s", G.iface_exists ? "exists" : "doesn't exist, waiting"); } /* else we assume it always exists, but don't mislead user * by potentially lying that it really exists *///.........这里部分代码省略.........
开发者ID:ArcSung,项目名称:busybox-1.22.1,代码行数:101,
示例27: watchdog_mainint watchdog_main(int argc, char **argv){ static const struct suffix_mult suffixes[] = { { "ms", 1 }, { "", 1000 }, { "", 0 } }; unsigned opts; unsigned stimer_duration; /* how often to restart */ unsigned htimer_duration = 60000; /* reboots after N ms if not restarted */ char *st_arg; char *ht_arg; opt_complementary = "=1"; /* must have exactly 1 argument */ opts = getopt32(argv, "Ft:T:", &st_arg, &ht_arg); /* We need to daemonize *before* opening the watchdog as many drivers * will only allow one process at a time to do so. Since daemonizing * is not perfect (child may run before parent finishes exiting), we * can't rely on parent exiting before us (let alone *cleanly* releasing * the watchdog fd -- something else that may not even be allowed). */ if (!(opts & OPT_FOREGROUND)) bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv); if (opts & OPT_HTIMER) htimer_duration = xatou_sfx(ht_arg, suffixes); stimer_duration = htimer_duration / 2; if (opts & OPT_STIMER) stimer_duration = xatou_sfx(st_arg, suffixes); bb_signals(BB_FATAL_SIGS, watchdog_shutdown); /* Use known fd # - avoid needing global 'int fd' */ xmove_fd(xopen(argv[argc - 1], O_WRONLY), 3); /* WDIOC_SETTIMEOUT takes seconds, not milliseconds */ htimer_duration = htimer_duration / 1000;#ifndef WDIOC_SETTIMEOUT# error WDIOC_SETTIMEOUT is not defined, cannot compile watchdog applet#else# if defined WDIOC_SETOPTIONS && defined WDIOS_ENABLECARD { static const int enable = WDIOS_ENABLECARD; ioctl_or_warn(3, WDIOC_SETOPTIONS, (void*) &enable); }# endif ioctl_or_warn(3, WDIOC_SETTIMEOUT, &htimer_duration);#endif#if 0 ioctl_or_warn(3, WDIOC_GETTIMEOUT, &htimer_duration); printf("watchdog: SW timer is %dms, HW timer is %ds/n", stimer_duration, htimer_duration * 1000);#endif while (1) { /* * Make sure we clear the counter before sleeping, * as the counter value is undefined at this point -- PFM */ write(3, "", 1); /* write zero byte */ usleep(stimer_duration * 1000L); } return EXIT_SUCCESS; /* - not reached, but gcc 4.2.1 is too dumb! */}
开发者ID:BezTebya,项目名称:busybox-w32,代码行数:67,
示例28: split_mainint split_main(int argc UNUSED_PARAM, char **argv){ unsigned suffix_len = 2; char *pfx; char *count_p; const char *sfx; off_t cnt = 1000; off_t remaining = 0; unsigned opt; ssize_t bytes_read, to_write; char *src; opt_complementary = "?2:a+"; /* max 2 args; -a N */ opt = getopt32(argv, "l:b:a:", &count_p, &count_p, &suffix_len); if (opt & SPLIT_OPT_l) cnt = XATOOFF(count_p); if (opt & SPLIT_OPT_b) // FIXME: also needs XATOOFF cnt = xatoull_sfx(count_p, IF_FEATURE_SPLIT_FANCY(split_suffixes) IF_NOT_FEATURE_SPLIT_FANCY(km_suffixes) ); sfx = "x"; argv += optind; if (argv[0]) { int fd; if (argv[1]) sfx = argv[1]; fd = xopen_stdin(argv[0]); xmove_fd(fd, STDIN_FILENO); } else { argv[0] = (char *) bb_msg_standard_input; } if (NAME_MAX < strlen(sfx) + suffix_len) bb_error_msg_and_die("suffix too long"); { char *char_p = xzalloc(suffix_len + 1); memset(char_p, 'a', suffix_len); pfx = xasprintf("%s%s", sfx, char_p); if (ENABLE_FEATURE_CLEAN_UP) free(char_p); } while (1) { bytes_read = safe_read(STDIN_FILENO, read_buffer, READ_BUFFER_SIZE); if (!bytes_read) break; if (bytes_read < 0) bb_simple_perror_msg_and_die(argv[0]); src = read_buffer; do { if (!remaining) { if (!pfx) bb_error_msg_and_die("suffixes exhausted"); xmove_fd(xopen(pfx, O_WRONLY | O_CREAT | O_TRUNC), 1); pfx = next_file(pfx, suffix_len); remaining = cnt; } if (opt & SPLIT_OPT_b) { /* split by bytes */ to_write = (bytes_read < remaining) ? bytes_read : remaining; remaining -= to_write; } else { /* split by lines */ /* can be sped up by using _memrchr_ * and writing many lines at once... */ char *end = memchr(src, '/n', bytes_read); if (end) { --remaining; to_write = end - src + 1; } else { to_write = bytes_read; } } xwrite(STDOUT_FILENO, src, to_write); bytes_read -= to_write; src += to_write; } while (bytes_read); } return EXIT_SUCCESS;}
开发者ID:ThinkIntegrate,项目名称:busybox,代码行数:86,
示例29: patch_mainint patch_main(int argc UNUSED_PARAM, char **argv){ int opts; int reverse, state = 0; char *oldname = NULL, *newname = NULL; char *opt_p, *opt_i; long oldlen = oldlen; /* for compiler */ long newlen = newlen; /* for compiler */ INIT_TT(); opts = getopt32(argv, FLAG_STR, &opt_p, &opt_i); argv += optind; reverse = opts & FLAG_REVERSE; TT.prefix = (opts & FLAG_PATHLEN) ? xatoi(opt_p) : 0; // can be negative! TT.filein = TT.fileout = -1; if (opts & FLAG_INPUT) { xmove_fd(xopen_stdin(opt_i), STDIN_FILENO); } else { if (argv[0] && argv[1]) { xmove_fd(xopen_stdin(argv[1]), STDIN_FILENO); } } if (argv[0]) { oldname = xstrdup(argv[0]); newname = xstrdup(argv[0]); } // Loop through the lines in the patch for(;;) { char *patchline; patchline = xmalloc_fgetline(stdin); if (!patchline) break; // Other versions of patch accept damaged patches, // so we need to also. if (!*patchline) { free(patchline); patchline = xstrdup(" "); } // Are we assembling a hunk? if (state >= 2) { if (*patchline==' ' || *patchline=='+' || *patchline=='-') { dlist_add(&TT.current_hunk, patchline); if (*patchline != '+') oldlen--; if (*patchline != '-') newlen--; // Context line? if (*patchline==' ' && state==2) TT.context++; else state=3; // If we've consumed all expected hunk lines, apply the hunk. if (!oldlen && !newlen) state = apply_one_hunk(); continue; } fail_hunk(); state = 0; continue; } // Open a new file? if (!strncmp("--- ", patchline, 4) || !strncmp("+++ ", patchline, 4)) { char *s, **name = reverse ? &newname : &oldname; int i; if (*patchline == '+') { name = reverse ? &oldname : &newname; state = 1; } finish_oldfile(); if (!argv[0]) { free(*name); // Trim date from end of filename (if any). We don't care. for (s = patchline+4; *s && *s!='/t'; s++) if (*s=='//' && s[1]) s++; i = atoi(s); if (i>1900 && i<=1970) *name = xstrdup("/dev/null"); else { *s = 0; *name = xstrdup(patchline+4); } } // We defer actually opening the file because svn produces broken // patches that don't signal they want to create a new file the // way the patch man page says, so you have to read the first hunk // and _guess_. // Start a new hunk? Usually @@ -oldline,oldlen +newline,newlen @@ // but a missing ,value means the value is 1. } else if (state == 1 && !strncmp("@@ -", patchline, 4)) { int i; char *s = patchline+4;//.........这里部分代码省略.........
开发者ID:qwerty1023,项目名称:wive-rtnl-firmware,代码行数:101,
注:本文中的xmove_fd函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ xmpp_debug函数代码示例 C++ xmmsv_unref函数代码示例 |