Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/libbb/xfuncs_printf.c

    r3232 r3621  
    113113}
    114114
     115void* FAST_FUNC xmemdup(const void *s, int n)
     116{
     117    return memcpy(xmalloc(n), s, n);
     118}
     119
    115120// Die if we can't open a file and return a FILE* to it.
    116121// Notice we haven't got xfread(), This is for use with fscanf() and friends.
     
    139144{
    140145    return xopen3(pathname, flags, 0666);
     146}
     147
     148// Warn if we can't open a file and return a fd.
     149int 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.
     161int FAST_FUNC open_or_warn(const char *pathname, int flags)
     162{
     163    return open3_or_warn(pathname, flags, 0666);
    141164}
    142165
     
    150173}
    151174
    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);
     175int 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;
    168190}
    169191
     
    352374}
    353375
     376void FAST_FUNC xsetegid(gid_t egid)
     377{
     378    if (setegid(egid)) bb_perror_msg_and_die("setegid");
     379}
     380
     381void FAST_FUNC xseteuid(uid_t euid)
     382{
     383    if (seteuid(euid)) bb_perror_msg_and_die("seteuid");
     384}
     385
    354386// Die if we can't chdir to a new path.
    355387void FAST_FUNC xchdir(const char *path)
     
    357389    if (chdir(path))
    358390        bb_perror_msg_and_die("can't change directory to '%s'", path);
     391}
     392
     393void FAST_FUNC xfchdir(int fd)
     394{
     395    if (fchdir(fd))
     396        bb_perror_msg_and_die("fchdir");
    359397}
    360398
     
    542580char* FAST_FUNC xmalloc_ttyname(int fd)
    543581{
    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);
    551587}
    552588
     
    624660}
    625661#endif
     662
     663void 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.