示例#1
0
void main(int argc,String *argv) {
  
  ArgParser a=ArgParser(argc,argv);
  a.com=Sconc(a.com,"[source directories] ");
  String dest=a.argafter("-dest","destination file location",Sconc(safegetenv("JPATH"),"/background.jpg"));

  // Get possible files
  List<String> fs;
  if (a.argsleft()==0) {
    fs.add(getfilesrecursive(Sconc(safegetenv("JPATH"),"/wallpapers/"))); // Default if no args
  }
  while (a.argsleft()) {
    String d=a.getarg();
    fs.add(getfilesrecursive(d));
  }
//  printf("%s\n",fs.toString());
  a.done();

  // Exclude those of wrong type
  List<String> types;
  types.add("jpg");
  types.add("jpeg");
  types.add("bmp");
  types.add("gif");
  types.add("tgz");
  types.add("gz");
  for (int i=1;i<=fs.len;i++) {
    String fname=fs.num(i);
    String ext=Safterlastorall(fname,".");
//    printf("%s has ext %s\n",fname,ext);
    if (    types.find(ext,&Sequiv)==0
         || Sinstr(fname,"wallpapers/tiles/")>0
         || Sinstr(fname,"wallpapers/small/")>0
         || Sinstr(fname,"wallpapers/naff/")>0
         || Sinstr(fname,"wallpapers/for/")>0
         || Sinstr(fname,"/babes/")>0
         || Sinstr(fname,"/fairies/")>0
         || Sinstr(fname,"/mermaids/")>0
         || Sinstr(fname,"/.xvpics/")>0 ) { // Case-insensitive search
//      printf("Didn't find extension %s\n",ext);
      fs.removenum(i);
      i--;
    }
  }

  // Choose a random file and symbolically link it
  randomise();
  int n=intrnd(1,fs.len);
  #ifdef DOS
  String call=Sformat("copy \"%s\" \"%s\"",fs.num(n),dest);
  #else
  String call=Sformat("ln -s -f \"%s\" \"%s\"",fs.num(n),dest);
  #endif
  system(call);
//  setenv("RANDOMFILENAME",fs.num(n),true);

}
示例#2
0
/* Compute and return a list of all directories that we should search when
 * trying to locate a module. We first look at the values of LD_LIBRARY_PATH
 * and DYLD_LIBRARY_PATH, and then finally fall back to looking into
 * /usr/lib and /lib. Since both of the environments variables can contain a
 * list of colon seperated paths, we simply concat them and the two other paths
 * into one big string, which we then can easily parse.
 * Splitting this string into the actual path list is done by getSearchPath()
 */
static const char * searchList()
{
    char * buf;
    const char * ldlp = safegetenv("LD_LIBRARY_PATH");
    const char * dyldlp = safegetenv("DYLD_LIBRARY_PATH");
    size_t    buf_size = strlen(ldlp) + strlen(dyldlp) + 35;
    buf = malloc(buf_size);
    if (buf == NULL) {
        return "";
    }
    snprintf(buf, buf_size, "%s:%s:/usr/local/lib:/lib:/usr/lib", dyldlp, ldlp);
    return buf;
}
示例#3
0
/* Compute and return a list of all directories that we should search when
 * trying to locate a module. We first look at the values of LD_LIBRARY_PATH
 * and DYLD_LIBRARY_PATH, and then finally fall back to looking into
 * /usr/lib and /lib. Since both of the environments variables can contain a
 * list of colon seperated paths, we simply concat them and the two other paths
 * into one big string, which we then can easily parse.
 * Splitting this string into the actual path list is done by getSearchPath()
 */
static const char *searchList()
{
	size_t buf_size;
	static char *buf=NULL;
	const char *ldlp = safegetenv("LD_LIBRARY_PATH");
	const char *dyldlp = safegetenv("DYLD_LIBRARY_PATH");
	const char *stdpath = getenv("DYLD_FALLBACK_LIBRARY_PATH");
	if (!stdpath)
		stdpath = "/usr/local/lib:/lib:/usr/lib";
	if (!buf)
	{	
		buf_size = strlen(ldlp) + strlen(dyldlp) + strlen(stdpath) + 4;
		buf = malloc(buf_size);
		snprintf(buf, buf_size, "%s%s%s%s%s%c", dyldlp, (dyldlp[0] ? ":" : ""), ldlp, (ldlp[0] ? ":" : ""),
				 stdpath, '\0');
	}
	return buf;
}
示例#4
0
str
agent_userdir (u_int32_t uid, bool create)
{
  int fd = open (".", O_RDONLY);
  if (fd < 0) {
    warn ("current working directory (.): %m\n");
    return NULL;
  }

  const char *tmpdir = safegetenv ("TMPDIR");
  if (!tmpdir || tmpdir[0] != '/')
    tmpdir = "/tmp";
  
  str ret;
  struct stat sb;
  uid_t myuid = getuid ();

  if (chdir (tmpdir) < 0)
    warn ("%s: %m\n", tmpdir);
  else if (stat (".", &sb) < 0)
    warn ("%s: %m\n", tmpdir);
  else if ((sb.st_mode & 022) && !(sb.st_mode & 01000))
    warn ("bad permissions on %s; chmod +t or set TMPDIR elsewhere", tmpdir);
  else if (myuid == uid)
    ret = agent_userdir_search (tmpdir, uid, create);
  else if (!myuid) {
    int fds[2];
    if (pipe (fds) < 0)
      warn ("pipe: %m\n");
    else if (pid_t pid = afork ()) {
      close (fds[1]);
      strbuf sb;
      while (sb.tosuio ()->input (fds[0]) > 0)
	;
      close (fds[0]);
      int status = 1;
      if (!waitpid (pid, &status, 0) && !status)
	ret = sb;
    }
    else {
      close (fds[0]);
      _exit (setuid (uid)
	     || !(ret = agent_userdir_search (tmpdir, uid, create))
	     || (write (fds[1], ret, ret.len ())
	         != implicit_cast<ssize_t> (ret.len ())));
    }
  }

  rc_ignore (fchdir (fd));
  close (fd);
  return ret ? str (strbuf ("%s/", tmpdir) << ret) : str (NULL);
}
示例#5
0
文件: sfsconst.C 项目: okws/sfslite
str
sfshostname ()
{
  str name = safegetenv ("SFS_HOSTNAME");
  if (!name)
    name = myname ();
  if (!name)
    fatal ("could not figure out host's fully-qualified domain name\n");
  mstr m (name.len ());
  for (u_int i = 0; i < name.len (); i++)
    m[i] = tolower (name[i]);
  return m;
}
示例#6
0
文件: sfsconst.C 项目: okws/sfslite
void
sfsconst_init (bool lite_mode)
{
  if (const_set)
    return;
  const_set = true;

  {
    char *p = safegetenv ("SFS_RELEASE");
    if (!p || !convertint (p, &sfs_release)) {
      str rel (strbuf () << "SFS_RELEASE=" << sfs_release);
      xputenv (const_cast<char*>(rel.cstr()));
    }
  }

#ifdef MAINTAINER
  if (char *p = safegetenv ("SFS_RUNINPLACE")) {
    runinplace = true;
    builddir = p;
    buildtmpdir = builddir << "/runinplace";
  }
  if (char *p = safegetenv ("SFS_ROOT"))
    if (*p == '/')
      sfsroot = p;
#endif /* MAINTAINER */
  sfsdevdb = strbuf ("%s/.devdb", sfsroot);

#ifdef MAINTAINER
  if (runinplace) {
    sfsdir = buildtmpdir;
    sfssockdir = sfsdir;
    etc3dir = etc1dir;
    etc1dir = sfsdir.cstr();
    etc2dir = xstrdup (str (builddir << "/etc"));
  }
#endif /* MAINTAINER */
  if (char *ps = safegetenv ("SFS_PORT"))
    if (int pv = atoi (ps))
      sfs_defport = pv;

  str sfs_config = safegetenv ("SFS_CONFIG");
  if (sfs_config && sfs_config[0] == '/') {
    if (!parseconfig (NULL, sfs_config))
      fatal << sfs_config << ": " << strerror (errno) << "\n";
  }
  else {
    if (!parseconfig (etc3dir, sfs_config)) {
      parseconfig (etc3dir, "sfs_config");
      if (!parseconfig (etc2dir, sfs_config)) {
	parseconfig (etc2dir, "sfs_config");
	if (!parseconfig (etc1dir, sfs_config)) 
	  parseconfig (etc1dir, "sfs_config");
      }
    }
  }

  if (!lite_mode) {
    if (!sfs_uid)
      idlookup (NULL, NULL);
  }

  if (char *p = getenv ("SFS_HASHCOST")) {
    sfs_hashcost = strtoi64 (p);
    if (sfs_hashcost > sfs_maxhashcost)
      sfs_hashcost = sfs_maxhashcost;
  }

  if (!getuid () && !runinplace) {
    mksfsdir (sfsdir, 0755);
    mksfsdir (sfssockdir, 0750);
  }
  else if (runinplace && access (sfsdir, 0) < 0) {
    struct stat sb;
    if (!stat (builddir, &sb)) {
      mode_t m = umask (0);
      if (!getuid ()) {
	if (pid_t pid = fork ())
	  waitpid (pid, NULL, 0);
	else {
	  umask (0);
	  setgid (sfs_gid);
	  setuid (sb.st_uid);
	  if (mkdir (sfsdir, 02770) >= 0)
	    rc_ignore (chown (sfsdir, (uid_t) -1, sfs_gid));
	  _exit (0);
	}
      }
      else
	mkdir (sfsdir, 0777);
      umask (m);
    }
  }
}
示例#7
0
文件: mtdispatch.C 项目: Keloran/okws
mtd_reporting_t::mtd_reporting_t ()
{
  const char *p = safegetenv ("DBPRX_REPORT_RPCS");
  if (p) set_rpc_reports (p);
}
示例#8
0
文件: spawn.C 项目: maxtaco/sfslite
#include "rxx.h"
#include <dirent.h>

str execdir (EXECDIR);
#ifdef MAINTAINER
str builddir;
str buildtmpdir;
#endif /* MAINTAINER */

static void
nop (int)
{
}

#ifdef MAINTAINER
bool afork_debug = safegetenv ("AFORK_DEBUG");
#endif /* MAINTAINER */

pid_t
afork ()
{
  if (pid_t pid = fork ())
    return pid;

  fatal_no_destruct = true;
  err_reset ();

  /* If we close/dup2 stderr before an exec, but the exec fails, we
   * still want warn/fatal to work so as to report the error. */
  if (errfd == 2) {
    int fd = dup (errfd);