X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fsrc%2Flsxid.c;h=bfcb47dbd81f75c9d45ca149ac83c89677821f8f;hb=a917f24ef7b003dcef54a3db2644cf9cb4bc2db2;hp=cc7cd18eed9a5f8340cdf0f9952d3f79982e9c0c;hpb=19f003f66c0d83ae8ade956fd2b357a109fc73e0;p=util-vserver.git diff --git a/util-vserver/src/lsxid.c b/util-vserver/src/lsxid.c index cc7cd18..bfcb47d 100644 --- a/util-vserver/src/lsxid.c +++ b/util-vserver/src/lsxid.c @@ -23,6 +23,7 @@ #include "fstool.h" #include "util.h" +#include #include #include @@ -33,6 +34,10 @@ #include #include #include +#include + +#define ENSC_WRAPPERS_STDLIB 1 +#include struct option const CMDLINE_OPTIONS[] = { @@ -41,7 +46,14 @@ CMDLINE_OPTIONS[] = { { 0,0,0,0 } }; -char const CMDLINE_OPTIONS_SHORT[] = "Radn"; +char const CMDLINE_OPTIONS_SHORT[] = "Radnx"; + +struct XidNameMapping { + xid_t xid; + char const * name; +}; + +static struct Vector xid_name_mapping; void showHelp(int fd, char const *cmd, int res) @@ -49,13 +61,14 @@ showHelp(int fd, char const *cmd, int res) WRITE_MSG(fd, "Usage: "); WRITE_STR(fd, cmd); WRITE_MSG(fd, - " [-Radn] [--] *\n\n" + " [-Radnx] [--] *\n\n" " Options:\n" " -R ... recurse through directories\n" " -a ... display files starting with '.' also\n" " -d ... list directories like other files instead of\n" " listing their content\n" " -n ... do not try to do xid -> vserver-name mapping\n" + " -x ... do not cross filesystems\n\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); exit(res); } @@ -74,34 +87,56 @@ showVersion() void fixupParams(struct Arguments UNUSED * args, int UNUSED argc) { + Vector_init(&xid_name_mapping, sizeof (struct XidNameMapping)); } -static xid_t -getFileContext(char const *name, struct stat const *exp_st) +static int +cmpMap(void const *xid_v, void const *map_v) { - int fd = open(name, O_RDONLY); - xid_t res; - - if (fd==-1) { - perror("open()"); - return VC_NOCTX; + xid_t const * const xid = xid_v; + struct XidNameMapping const * const map = map_v; + + return *xid - map->xid; +} + +static char const * +lookupContext(xid_t xid) +{ + struct XidNameMapping *res; + + res = Vector_search(&xid_name_mapping, &xid, cmpMap); + + if (res==0) { + vcCfgStyle style = vcCFG_AUTO; + char const * vcfg = vc_getVserverByCtx(xid, &style, 0); + + res = Vector_insert(&xid_name_mapping, &xid, cmpMap); + if (vcfg) res->name = vc_getVserverName(vcfg, style); + else res->name = 0; + res->xid = xid; + + free(const_cast(char *)(vcfg)); } - if (exp_st) - checkForRace(fd, name, exp_st); + assert(res!=0); + + return res->name; +} - res = vc_X_get_filecontext(fd); - if (res==VC_NOCTX) - perror("vc_X_get_filecontext()"); +static xid_t +getFileContext(char const *name) +{ + xid_t res; + uint32_t mask = VC_IATTR_XID; - close(fd); + if (vc_get_iattr(name, &res, 0, &mask)==-1) + perror("vc_get_iattr()"); - return res; + return (mask&VC_IATTR_XID) ? res : VC_NOCTX; } bool -handleFile(char const *name, char const *display_name, - struct stat const *exp_st) +handleFile(char const *name, char const *display_name) { xid_t ctx = 0; char buf[MAX(sizeof(ctx)*3+1, 20)]; @@ -109,31 +144,28 @@ handleFile(char const *name, char const *display_name, memset(buf, ' ', sizeof buf); - if (S_ISLNK(exp_st->st_mode)) { - memcpy(buf, "-------", 7); +#if 1 + ctx = getFileContext(name); +#else +# warning Compiling in debug-code + ctx = random() % 10 + 49213; +#endif + + if (ctx==VC_NOCTX) { + memcpy(buf, "!!ERR!!", 7); write(1, buf, sizeof buf); need_write = false; } - else { - ctx = getFileContext(name, exp_st); - - if (ctx==VC_NOCTX) { - memcpy(buf, "!!ERR!!", 7); - write(1, buf, sizeof buf); + else if (global_args->do_mapping) { + char const * vname = lookupContext(ctx); + if (!vname) buf[0] = '\0'; + else { + size_t l = strlen(vname); + if (ldo_mapping) { - char const * vname = vc_getVserverByCtx(ctx, 0,0); - if (!vname) buf[0] = '\0'; - else { - size_t l = strlen(vname); - if (l