Deleted Added
full compact
wordexp.c (253581) wordexp.c (254977)
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

--- 25 unchanged lines hidden (view full) ---

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
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

--- 25 unchanged lines hidden (view full) ---

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
42__FBSDID("$FreeBSD: head/lib/libc/gen/wordexp.c 253581 2013-07-23 21:09:26Z jilles $");
42__FBSDID("$FreeBSD: head/lib/libc/gen/wordexp.c 254977 2013-08-27 21:47:01Z jilles $");
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).

--- 65 unchanged lines hidden (view full) ---

116 int serrno; /* errno to return */
117 char *np, *p; /* Handy pointers */
118 char *nstrings; /* Temporary for realloc() */
119 char **nwv; /* Temporary for realloc() */
120 sigset_t newsigblock, oldsigblock;
121
122 serrno = errno;
123
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).

--- 65 unchanged lines hidden (view full) ---

116 int serrno; /* errno to return */
117 char *np, *p; /* Handy pointers */
118 char *nstrings; /* Temporary for realloc() */
119 char **nwv; /* Temporary for realloc() */
120 sigset_t newsigblock, oldsigblock;
121
122 serrno = errno;
123
124 if (pipe(pdes) < 0)
124 if (pipe2(pdes, O_CLOEXEC) < 0)
125 return (WRDE_NOSPACE); /* XXX */
126 (void)sigemptyset(&newsigblock);
127 (void)sigaddset(&newsigblock, SIGCHLD);
128 (void)_sigprocmask(SIG_BLOCK, &newsigblock, &oldsigblock);
129 if ((pid = fork()) < 0) {
130 serrno = errno;
131 _close(pdes[0]);
132 _close(pdes[1]);
133 (void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL);
134 errno = serrno;
135 return (WRDE_NOSPACE); /* XXX */
136 }
137 else if (pid == 0) {
138 /*
139 * We are the child; just get /bin/sh to run the wordexp
140 * builtin on `words'.
141 */
142 (void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL);
125 return (WRDE_NOSPACE); /* XXX */
126 (void)sigemptyset(&newsigblock);
127 (void)sigaddset(&newsigblock, SIGCHLD);
128 (void)_sigprocmask(SIG_BLOCK, &newsigblock, &oldsigblock);
129 if ((pid = fork()) < 0) {
130 serrno = errno;
131 _close(pdes[0]);
132 _close(pdes[1]);
133 (void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL);
134 errno = serrno;
135 return (WRDE_NOSPACE); /* XXX */
136 }
137 else if (pid == 0) {
138 /*
139 * We are the child; just get /bin/sh to run the wordexp
140 * builtin on `words'.
141 */
142 (void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL);
143 _close(pdes[0]);
144 if (_dup2(pdes[1], STDOUT_FILENO) < 0)
143 if ((pdes[1] != STDOUT_FILENO ?
144 _dup2(pdes[1], STDOUT_FILENO) :
145 _fcntl(pdes[1], F_SETFD, 0)) < 0)
145 _exit(1);
146 _exit(1);
146 _close(pdes[1]);
147 execl(_PATH_BSHELL, "sh", flags & WRDE_UNDEF ? "-u" : "+u",
148 "-c", "eval \"$1\";eval \"wordexp $2\"", "",
149 flags & WRDE_SHOWERR ? "" : "exec 2>/dev/null", words,
150 (char *)NULL);
151 _exit(1);
152 }
153
154 /*

--- 188 unchanged lines hidden ---
147 execl(_PATH_BSHELL, "sh", flags & WRDE_UNDEF ? "-u" : "+u",
148 "-c", "eval \"$1\";eval \"wordexp $2\"", "",
149 flags & WRDE_SHOWERR ? "" : "exec 2>/dev/null", words,
150 (char *)NULL);
151 _exit(1);
152 }
153
154 /*

--- 188 unchanged lines hidden ---