wordexp.c (286941) | wordexp.c (287292) |
---|---|
1/*- 2 * Copyright (c) 2002 Tim J. Robbins. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 24 unchanged lines hidden (view full) --- 33#include <paths.h> 34#include <signal.h> 35#include <stdio.h> 36#include <stdlib.h> 37#include <string.h> 38#include <unistd.h> 39#include <wordexp.h> 40#include "un-namespace.h" | 1/*- 2 * Copyright (c) 2002 Tim J. Robbins. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 24 unchanged lines hidden (view full) --- 33#include <paths.h> 34#include <signal.h> 35#include <stdio.h> 36#include <stdlib.h> 37#include <string.h> 38#include <unistd.h> 39#include <wordexp.h> 40#include "un-namespace.h" |
41#include "libc_private.h" |
|
41 | 42 |
42__FBSDID("$FreeBSD: head/lib/libc/gen/wordexp.c 286941 2015-08-19 20:31:03Z jilles $"); | 43__FBSDID("$FreeBSD: head/lib/libc/gen/wordexp.c 287292 2015-08-29 14:25:01Z kib $"); |
43 44static int we_askshell(const char *, wordexp_t *, int); 45static int we_check(const char *, int); 46 47/* 48 * wordexp -- 49 * Perform shell word expansion on `words' and place the resulting list 50 * of words in `we'. See wordexp(3). --- 71 unchanged lines hidden (view full) --- 122 123 serrno = errno; 124 ifs = getenv("IFS"); 125 126 if (pipe2(pdes, O_CLOEXEC) < 0) 127 return (WRDE_NOSPACE); /* XXX */ 128 (void)sigemptyset(&newsigblock); 129 (void)sigaddset(&newsigblock, SIGCHLD); | 44 45static int we_askshell(const char *, wordexp_t *, int); 46static int we_check(const char *, int); 47 48/* 49 * wordexp -- 50 * Perform shell word expansion on `words' and place the resulting list 51 * of words in `we'. See wordexp(3). --- 71 unchanged lines hidden (view full) --- 123 124 serrno = errno; 125 ifs = getenv("IFS"); 126 127 if (pipe2(pdes, O_CLOEXEC) < 0) 128 return (WRDE_NOSPACE); /* XXX */ 129 (void)sigemptyset(&newsigblock); 130 (void)sigaddset(&newsigblock, SIGCHLD); |
130 (void)_sigprocmask(SIG_BLOCK, &newsigblock, &oldsigblock); | 131 (void)__libc_sigprocmask(SIG_BLOCK, &newsigblock, &oldsigblock); |
131 if ((pid = fork()) < 0) { 132 serrno = errno; 133 _close(pdes[0]); 134 _close(pdes[1]); | 132 if ((pid = fork()) < 0) { 133 serrno = errno; 134 _close(pdes[0]); 135 _close(pdes[1]); |
135 (void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); | 136 (void)__libc_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); |
136 errno = serrno; 137 return (WRDE_NOSPACE); /* XXX */ 138 } 139 else if (pid == 0) { 140 /* 141 * We are the child; make /bin/sh expand `words'. 142 */ | 137 errno = serrno; 138 return (WRDE_NOSPACE); /* XXX */ 139 } 140 else if (pid == 0) { 141 /* 142 * We are the child; make /bin/sh expand `words'. 143 */ |
143 (void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); | 144 (void)__libc_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); |
144 if ((pdes[1] != STDOUT_FILENO ? 145 _dup2(pdes[1], STDOUT_FILENO) : 146 _fcntl(pdes[1], F_SETFD, 0)) < 0) 147 _exit(1); 148 execl(_PATH_BSHELL, "sh", flags & WRDE_UNDEF ? "-u" : "+u", 149 "-c", "IFS=$1;eval \"$2\";eval \"echo;set -- $3\";" 150 "IFS=;a=\"$*\";printf '%08x' \"$#\" \"${#a}\";" 151 "printf '%s\\0' \"$@\"", --- 65 unchanged lines hidden (view full) --- 217 } 218 219 error = 0; 220cleanup: 221 _close(pdes[0]); 222 do 223 wpid = _waitpid(pid, &status, 0); 224 while (wpid < 0 && errno == EINTR); | 145 if ((pdes[1] != STDOUT_FILENO ? 146 _dup2(pdes[1], STDOUT_FILENO) : 147 _fcntl(pdes[1], F_SETFD, 0)) < 0) 148 _exit(1); 149 execl(_PATH_BSHELL, "sh", flags & WRDE_UNDEF ? "-u" : "+u", 150 "-c", "IFS=$1;eval \"$2\";eval \"echo;set -- $3\";" 151 "IFS=;a=\"$*\";printf '%08x' \"$#\" \"${#a}\";" 152 "printf '%s\\0' \"$@\"", --- 65 unchanged lines hidden (view full) --- 218 } 219 220 error = 0; 221cleanup: 222 _close(pdes[0]); 223 do 224 wpid = _waitpid(pid, &status, 0); 225 while (wpid < 0 && errno == EINTR); |
225 (void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); | 226 (void)__libc_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); |
226 if (error != 0) { 227 errno = serrno; 228 return (error); 229 } 230 if (wpid < 0 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) 231 return (WRDE_NOSPACE); /* abort for unknown reason */ 232 233 /* --- 124 unchanged lines hidden --- | 227 if (error != 0) { 228 errno = serrno; 229 return (error); 230 } 231 if (wpid < 0 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) 232 return (WRDE_NOSPACE); /* abort for unknown reason */ 233 234 /* --- 124 unchanged lines hidden --- |