Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/libbb/xfuncs_printf.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/libbb/xfuncs_printf.c
r3232 r3621 113 113 } 114 114 115 void* FAST_FUNC xmemdup(const void *s, int n) 116 { 117 return memcpy(xmalloc(n), s, n); 118 } 119 115 120 // Die if we can't open a file and return a FILE* to it. 116 121 // Notice we haven't got xfread(), This is for use with fscanf() and friends. … … 139 144 { 140 145 return xopen3(pathname, flags, 0666); 146 } 147 148 // Warn if we can't open a file and return a fd. 149 int FAST_FUNC open3_or_warn(const char *pathname, int flags, int mode) 150 { 151 int ret; 152 153 ret = open(pathname, flags, mode); 154 if (ret < 0) { 155 bb_perror_msg("can't open '%s'", pathname); 156 } 157 return ret; 158 } 159 160 // Warn if we can't open a file and return a fd. 161 int FAST_FUNC open_or_warn(const char *pathname, int flags) 162 { 163 return open3_or_warn(pathname, flags, 0666); 141 164 } 142 165 … … 150 173 } 151 174 152 // Warn if we can't open a file and return a fd. 153 int FAST_FUNC open3_or_warn(const char *pathname, int flags, int mode) 154 { 155 int ret; 156 157 ret = open(pathname, flags, mode); 158 if (ret < 0) { 159 bb_perror_msg("can't open '%s'", pathname); 160 } 161 return ret; 162 } 163 164 // Warn if we can't open a file and return a fd. 165 int FAST_FUNC open_or_warn(const char *pathname, int flags) 166 { 167 return open3_or_warn(pathname, flags, 0666); 175 int FAST_FUNC xopen_as_uid_gid(const char *pathname, int flags, uid_t u, gid_t g) 176 { 177 int fd; 178 uid_t old_euid = geteuid(); 179 gid_t old_egid = getegid(); 180 181 xsetegid(g); 182 xseteuid(u); 183 184 fd = xopen(pathname, flags); 185 186 xseteuid(old_euid); 187 xsetegid(old_egid); 188 189 return fd; 168 190 } 169 191 … … 352 374 } 353 375 376 void FAST_FUNC xsetegid(gid_t egid) 377 { 378 if (setegid(egid)) bb_perror_msg_and_die("setegid"); 379 } 380 381 void FAST_FUNC xseteuid(uid_t euid) 382 { 383 if (seteuid(euid)) bb_perror_msg_and_die("seteuid"); 384 } 385 354 386 // Die if we can't chdir to a new path. 355 387 void FAST_FUNC xchdir(const char *path) … … 357 389 if (chdir(path)) 358 390 bb_perror_msg_and_die("can't change directory to '%s'", path); 391 } 392 393 void FAST_FUNC xfchdir(int fd) 394 { 395 if (fchdir(fd)) 396 bb_perror_msg_and_die("fchdir"); 359 397 } 360 398 … … 542 580 char* FAST_FUNC xmalloc_ttyname(int fd) 543 581 { 544 char *buf = xzalloc(128); 545 int r = ttyname_r(fd, buf, 127); 546 if (r) { 547 free(buf); 548 buf = NULL; 549 } 550 return buf; 582 char buf[128]; 583 int r = ttyname_r(fd, buf, sizeof(buf) - 1); 584 if (r) 585 return NULL; 586 return xstrdup(buf); 551 587 } 552 588 … … 624 660 } 625 661 #endif 662 663 void FAST_FUNC xvfork_parent_waits_and_exits(void) 664 { 665 pid_t pid; 666 667 fflush_all(); 668 pid = xvfork(); 669 if (pid > 0) { 670 /* Parent */ 671 int exit_status = wait_for_exitstatus(pid); 672 if (WIFSIGNALED(exit_status)) 673 kill_myself_with_sig(WTERMSIG(exit_status)); 674 _exit(WEXITSTATUS(exit_status)); 675 } 676 /* Child continues */ 677 }
Note:
See TracChangeset
for help on using the changeset viewer.