File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -425,6 +425,8 @@ extern int path_inside_repo(const char *prefix, const char *path);
425425extern int set_git_dir_init (const char * git_dir , const char * real_git_dir , int );
426426extern int init_db (const char * template_dir , unsigned int flags );
427427
428+ extern void sanitize_stdfds (void );
429+
428430#define alloc_nr (x ) (((x)+16)*3/2)
429431
430432/*
Original file line number Diff line number Diff line change @@ -1047,18 +1047,6 @@ static int service_loop(struct socketlist *socklist)
10471047 }
10481048}
10491049
1050- /* if any standard file descriptor is missing open it to /dev/null */
1051- static void sanitize_stdfds (void )
1052- {
1053- int fd = open ("/dev/null" , O_RDWR , 0 );
1054- while (fd != -1 && fd < 2 )
1055- fd = dup (fd );
1056- if (fd == -1 )
1057- die_errno ("open /dev/null or dup failed" );
1058- if (fd > 2 )
1059- close (fd );
1060- }
1061-
10621050#ifdef NO_POSIX_GOODIES
10631051
10641052struct credentials ;
Original file line number Diff line number Diff line change @@ -525,6 +525,13 @@ int main(int argc, char **av)
525525 if (!cmd )
526526 cmd = "git-help" ;
527527
528+ /*
529+ * Always open file descriptors 0/1/2 to avoid clobbering files
530+ * in die(). It also avoids messing up when the pipes are dup'ed
531+ * onto stdin/stdout/stderr in the child processes we spawn.
532+ */
533+ sanitize_stdfds ();
534+
528535 git_setup_gettext ();
529536
530537 /*
Original file line number Diff line number Diff line change @@ -908,3 +908,15 @@ const char *resolve_gitdir(const char *suspect)
908908 return suspect ;
909909 return read_gitfile (suspect );
910910}
911+
912+ /* if any standard file descriptor is missing open it to /dev/null */
913+ void sanitize_stdfds (void )
914+ {
915+ int fd = open ("/dev/null" , O_RDWR , 0 );
916+ while (fd != -1 && fd < 2 )
917+ fd = dup (fd );
918+ if (fd == -1 )
919+ die_errno ("open /dev/null or dup failed" );
920+ if (fd > 2 )
921+ close (fd );
922+ }
Original file line number Diff line number Diff line change @@ -147,7 +147,6 @@ int main(int argc, char **argv)
147147 char * prog ;
148148 const char * * user_argv ;
149149 struct commands * cmd ;
150- int devnull_fd ;
151150 int count ;
152151
153152 git_setup_gettext ();
@@ -156,15 +155,10 @@ int main(int argc, char **argv)
156155
157156 /*
158157 * Always open file descriptors 0/1/2 to avoid clobbering files
159- * in die(). It also avoids not messing up when the pipes are
160- * dup'ed onto stdin/stdout/stderr in the child processes we spawn.
158+ * in die(). It also avoids messing up when the pipes are dup'ed
159+ * onto stdin/stdout/stderr in the child processes we spawn.
161160 */
162- devnull_fd = open ("/dev/null" , O_RDWR );
163- while (devnull_fd >= 0 && devnull_fd <= 2 )
164- devnull_fd = dup (devnull_fd );
165- if (devnull_fd == -1 )
166- die_errno ("opening /dev/null failed" );
167- close (devnull_fd );
161+ sanitize_stdfds ();
168162
169163 /*
170164 * Special hack to pretend to be a CVS server
You can’t perform that action at this time.
0 commit comments