This repository was archived by the owner on Nov 9, 2017. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +24
-21
lines changed Expand file tree Collapse file tree 5 files changed +24
-21
lines changed 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);
425
425
extern int set_git_dir_init (const char * git_dir , const char * real_git_dir , int );
426
426
extern int init_db (const char * template_dir , unsigned int flags );
427
427
428
+ extern void sanitize_stdfds (void );
429
+
428
430
#define alloc_nr (x ) (((x)+16)*3/2)
429
431
430
432
/*
Original file line number Diff line number Diff line change @@ -1047,18 +1047,6 @@ static int service_loop(struct socketlist *socklist)
1047
1047
}
1048
1048
}
1049
1049
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
-
1062
1050
#ifdef NO_POSIX_GOODIES
1063
1051
1064
1052
struct credentials ;
Original file line number Diff line number Diff line change @@ -525,6 +525,13 @@ int main(int argc, char **av)
525
525
if (!cmd )
526
526
cmd = "git-help" ;
527
527
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
+
528
535
git_setup_gettext ();
529
536
530
537
/*
Original file line number Diff line number Diff line change @@ -908,3 +908,15 @@ const char *resolve_gitdir(const char *suspect)
908
908
return suspect ;
909
909
return read_gitfile (suspect );
910
910
}
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)
147
147
char * prog ;
148
148
const char * * user_argv ;
149
149
struct commands * cmd ;
150
- int devnull_fd ;
151
150
int count ;
152
151
153
152
git_setup_gettext ();
@@ -156,15 +155,10 @@ int main(int argc, char **argv)
156
155
157
156
/*
158
157
* 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.
161
160
*/
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 ();
168
162
169
163
/*
170
164
* Special hack to pretend to be a CVS server
You can’t perform that action at this time.
0 commit comments