X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fwgt.c;h=980719b3ddc03e1fdc303b4a5aca9a4ec78ac01b;hb=12a227a2fc574cf0fd560453e1cdd15c50550abb;hp=1ae1a1302755201cb55cec09ae615fe3a2e36386;hpb=a4f840ada2b1c005e39f1c7ff0ce442a8c9221ff;p=src%2Fapp-framework-main.git diff --git a/src/wgt.c b/src/wgt.c index 1ae1a13..980719b 100644 --- a/src/wgt.c +++ b/src/wgt.c @@ -132,12 +132,10 @@ int wgt_connectat(struct wgt *wgt, int dirfd, const char *pathname) assert(wgt); - rfd = dirfd; - if (pathname) { - rfd = openat(rfd, pathname, O_PATH|O_DIRECTORY); - if (rfd < 0) - return rfd; - } + rfd = (pathname && *pathname) ? openat(dirfd, pathname, O_PATH|O_DIRECTORY) : dup(dirfd); + if (rfd < 0) + return rfd; + if (wgt->rootfd >= 0) close(wgt->rootfd); wgt->rootfd = rfd; @@ -149,6 +147,18 @@ int wgt_connect(struct wgt *wgt, const char *pathname) return wgt_connectat(wgt, AT_FDCWD, pathname); } +struct wgt *wgt_createat(int dirfd, const char *pathname) +{ + struct wgt *wgt = wgt_create(); + if (wgt) { + if (wgt_connectat(wgt, dirfd, pathname)) { + wgt_unref(wgt); + wgt = NULL; + } + } + return wgt; +} + int wgt_is_connected(struct wgt *wgt) { assert(wgt);