コード例 #1
0
ファイル: db_myd.c プロジェクト: tardyp/amake
/***************************************************************************
 * This function performs the database access for a "get"                  *
 * command. It builds an SQL query, submits it, and processes              *
 * the result. The result is a zero-terminated array of                    *
 * strings, where each string is a path in the cache of a                  *
 * candidate target. For example:                                          *
 *                                                                         *
 *     /tmp/tcd/buff/spud/2010-04-20/25245/14:46:39/foo.o                  *
 *                                                                         *
 * Arguments:                                                              *
 *     name = target name                                                  *
 *         (e.g., x/y/z/foo.o)                                             *
 *     arch = target architecture                                          *
 *         (e.g., "Linux_i686_2.6.30.10-105.fc11.i686.PAE")                *
 *     cmdsum = checksum of shell commands that build target               *
 *         (e.g., "gcc -c x/y/z/foo.c")                                    *
 ***************************************************************************/
DB_DCL(get,myd_) {
  char *query;
  query=vstrcat("select distinct cachedir from entries where "
		"name = "  ,"'",name,"'"," and ",
		"arch = "  ,"'",arch,"'"," and ",
		"cmdsum = ","'",cmdsum,"';",
		NULL);
  DEBUG("in db_myd_get(), query=\"%s\"",query);
  if (mysql_query(conn,query))
    ERR(vstrcat("db_myd_get(): ",mysql_error(conn),NULL));
  free(query);
  MYSQL_RES *result=mysql_store_result(conn);
  if (!result)
    ERR(vstrcat("db_myd_get(): ","use_result: ",mysql_error(conn),NULL));
  int n=mysql_num_rows(result);
  char **cachedirs=(char **)malloc((n+1)*sizeof(char *));
  if (!cachedirs)
    ERR("db_myd_get(): malloc() failed");
  int i;
  for (i=0; i<n; i++) {
    MYSQL_ROW row=mysql_fetch_row(result);
    cachedirs[i]=str_dup(row[0]);
  }
  cachedirs[i]=0;
  mysql_free_result(result);
  DEBUG("db_myd_get() done, %d in cache",n);
  return cachedirs;
}
コード例 #2
0
ファイル: db_myd.c プロジェクト: tardyp/amake
/***************************************************************************
 * This function simply opens the database connection.                     *
 ***************************************************************************/
DB_DCL(open,myd_) {
  DEBUG("in db_myd_open()");
  conn=mysql_init(0);
  if (!conn)
    ERR(vstrcat("mysql_init(): ",mysql_error(conn),NULL));
  if (!mysql_real_connect(conn,0,opt_myd_user(),0,opt_dbname(),0,0,0))
    ERR(vstrcat("db_myd_open(): ",mysql_error(conn),NULL));
  DEBUG("db_myd_open() done");
  return 0;
}
コード例 #3
0
ファイル: 4-9.c プロジェクト: wxiaodong0829/aka_edu_learned
int main(void)
{
   vstrcat("hello", "world", "I", "you", "NULL"); 

   return 0;

}
コード例 #4
0
ファイル: test9.c プロジェクト: wxiaodong0829/aka_edu_learned
int main(void)
{
	char *p;
	p=vstrcat("hello world"," china "," where are you ",NULL);
	printf("%s\n",p);

	return 0;
}
コード例 #5
0
ファイル: db_myd.c プロジェクト: tardyp/amake
/***************************************************************************
 * This function logs a database access.  It builds an SQL                 *
 * "insert" query, and submits it.                                         *
 *                                                                         *
 * Arguments:                                                              *
 *     op = operation                                                      *
 *         (e.g., "get")                                                   *
 *     date = current date: "yyyy-mm-dd"                                   *
 *     time = current time: "hh:mm:ss"                                     *
 *     name = target name                                                  *
 *         (e.g., x/y/z/foo.o)                                             *
 *     cwd = current working directory                                     *
 *         (e.g., "/home/buff/foo")                                        *
 *     result = result of access                                           *
 *         (e.g., "success").                                              *
 ***************************************************************************/
DB_DCL(log,myd_) {
  if (!opt_dblog())
    return 0;
  char *query=vstrcat("insert into log values ("
		      "'",op,"',",
		      "'",date," ",time,"',",
		      "'",str_host(),"',",
		      "'",str_user(),"',",
		      "'",name,"',",
		      "'",cwd,"',",
		      "'",result,"');",
		      NULL);
  if (mysql_query(conn,query))
    ERR(vstrcat("db_myd_log(): ",mysql_error(conn),NULL));
  free(query);
  return 0;
}
コード例 #6
0
ファイル: db_myd.c プロジェクト: tardyp/amake
/***************************************************************************
 * This function performs the database access for a "put"                  *
 * command.                                                                *
 *                                                                         *
 * First, it builds an SQL "select" query, submits it, and                 *
 * processes the result. This determines if the target is                  *
 * already in the database. If so, it returns 0.                           *
 *                                                                         *
 * If not, it then builds an SQL "insert" query, submits it,               *
 * and returns 1.                                                          *
 *                                                                         *
 * Arguments:                                                              *
 *     date = current date: "yyyy-mm-dd"                                   *
 *     time = current time: "hh:mm:ss"                                     *
 *     name = target name                                                  *
 *         (e.g., x/y/z/foo.o)                                             *
 *     arch = target architecture                                          *
 *         (e.g., "Linux_i686_2.6.30.10-105.fc11.i686.PAE")                *
 *     chksum = checksum of content of target file, to avoid               *
 *         duplicate database/cache entries                                *
 *         (e.g., "x/y/z/foo.c")                                           *
 *     cmdsum = checksum of shell commands that build target               *
 *         (e.g., "gcc -c x/y/z/foo.c")                                    *
 *     cachedir = path in the cache of the target                          *
 *         (e.g., "/tmp/tcd/buff/spud/2010-04-20/25245/14:46:39/foo.o")    *
 ***************************************************************************/
DB_DCL(put,myd_) {
  DEBUG("in db_myd_put(\"%s\",\"%s\",\"%s\",\"%s\",\"%s\")",
	name,arch,chksum,cmdsum,cachedir);
  char *query;
  query=vstrcat("select distinct cachedir from entries where "
  		"name = "  ,"'",name,"'"  ," and ",
  		"arch = "  ,"'",arch,"'"  ," and ",
  		"chksum = ","'",chksum,"'"," and ",
  		"cmdsum = ","'",cmdsum,"';",
  		NULL);
  DEBUG("in db_myd_put(), query=\"%s\"",query);
  if (mysql_query(conn,query))
    ERR(vstrcat("db_myd_put(): ","select: ",mysql_error(conn),NULL));
  free(query);
  MYSQL_RES *result=mysql_use_result(conn);
  if (!result)
    ERR(vstrcat("db_myd_put(): ","use_result: ",mysql_error(conn),NULL));
  MYSQL_ROW row=mysql_fetch_row(result);
  mysql_free_result(result);
  if (row) {
    DEBUG("db_myd_put() done, already in cache");
    return 0;
  }
  query=vstrcat("insert into entries values ("
		"'",date," ",time,"',",
		"'",name,"',",
		"'",arch,"',",
		"'",chksum,"',",
		"'",cmdsum,"',",
		"'",cachedir,"');",
		NULL);
  DEBUG("in db_myd_put(), query=\"%s\"",query);
  if (mysql_query(conn,query))
    ERR(vstrcat("db_myd_put(): ","insert: ",mysql_error(conn),NULL));
  free(query);
  DEBUG("db_myd_put() done, now in cache");
  return 1;
}
コード例 #7
0
ファイル: strbuf.cpp プロジェクト: stevenknown/xoc
void StrBuf::vsprint(CHAR const* format, va_list args)
{
    clean();
    vstrcat(format, args);
}
コード例 #8
0
ファイル: run-as.c プロジェクト: kinkome/kinko-sys
void execv_in_app(const char* username, const char* appname, const char* arg0, char** argv) {
	if(username)
		switch_to_user(username);

	const char* kinko_root = getenv("KINKO_ROOT");
	if(!kinko_root) {
		kinko_root = Cwd();
		fprintf(stderr, "KINKO_ROOT environment setting missing; falling back to current dir: %s\n", kinko_root);
	}
	
	/*
	 * Fetch system settings to build environment for new process.
	 */
	const char* pw_shell = "/bin/false";

	/*
	 * The homedir is the root dir of the requested app.
	 * If the username is "kinko-<name>", then the homedir is "<kinko_root>/apps/<name>"
	 */
	const char* homedir = vstrcat(kinko_root, "/apps/", appname, 0);
	
	/*
	 * Clear environment. This implements a simple variant of sudo's env_reset
	 * function.
	 *
	 * Note: while sudo falls back to setting TERM, PATH, HOME, MAIL, SHELL,
	 * LOGNAME, USER, USERNAME we skp TERM and MAIL.
	 */

	static const int MAX_ENV_ENTRIES = 128;
	char* env[MAX_ENV_ENTRIES];
	char** envp = env;

	/*
	 * get initial path.
	 *
	 * Note that /usr/local/bin is in the path, because that allows for a
	 * system-wide installation of various interpreters even when they are
	 * not packaged by the system's package manager.
	 */
	const char* path = "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin";

	/*
	 * set ruby environment.
	 *
	 * The following code should make --no-print-directory sure that the new user will have gems
	 * installed in a private location. Note that a proper ruby installation
	 * must be installed system-wide; if nothing else works then in
	 * /usr/local/bin.
	 */

	path = vstrcat(homedir, "/bin"           ":", path, 0);
	path = vstrcat(homedir, "/var/bin"       ":", path, 0);
	path = vstrcat(homedir, "/var/gems/bin"  ":", path, 0);

	*envp++ = vstrcat("GEM_HOME=", homedir, "/var/gems", 0);
	*envp++ = vstrcat("GEM_PATH=", homedir, "/var/gems", 0);

	/*
	 * If there is a Gemfile in $homedir/Gemfile, we remember that in the
	 * environment. This make --no-print-directorys sure that bundler finds its Gemfile even
	 * when in the wrong directory; but it also prevents to run multiple
	 * ruby-based apps with different gemsets.
	 */
	/*
	{
		const char* gemfile = vstrcat(homedir, "/Gemfile", 0);

		struct stat stat_buf;
		if(!stat(gemfile, &stat_buf)) {
			(void)0;
			*envp++ = vstrcat("BUNDLE_GEMFILE=", gemfile, 0);
		}
	}
	*/

	*envp = 0;

	/*
	 * set KINKO environment entries
	 */
	*envp++ = vstrcat("KINKO_ROOT=", kinko_root, 0);
	path = vstrcat(kinko_root, "/sbin:", path, 0);
	path = vstrcat(kinko_root, "/bin:", path, 0);
	*envp++ = vstrcat("JIT_HOME=", kinko_root, "/var/jit", 0);

	/*
	 * set base entries
	 */
	
	*envp++ = "TMPDIR=/tmp";
	*envp++ = vstrcat("PATH=", path, 0);
	*envp++ = vstrcat("HOME=", homedir, 0);
	*envp++ = vstrcat("SHELL=", pw_shell, 0);

#if STRICT_MODE
	*envp++ = vstrcat("LOGNAME=", username, 0);
	*envp++ = vstrcat("USER="******"USERNAME="******"Cannot chdir into homedir %s\n", homedir);
		perror(homedir);
	}

	/*
	 * set umask. By default an application should not create files writeable
	 * by others.
	 */
	umask(S_IWGRP | S_IWOTH);

	/*
	 * start program.
	 */
	execve(arg0, argv, env);
	die(arg0);
}
コード例 #9
0
ファイル: ex05.c プロジェクト: rwils/programming_exercises
int main(void)
{
	char *string = vstrcat("one", " two", " three\n", (char *) NULL);
	printf(string);
}
コード例 #10
0
ファイル: blang-c.c プロジェクト: sabrown256/pactnew
static void c_emit_types_hdr(FILE *fh, der_list *sl,
			     const char *pck, int ni, int fl)
   {int i, nc;
    char a[BFLRG];
    char *mbr, *p;
    mbrdes *md;
    tn_list *tl;

    if (fl == TRUE)
       {fprintf(fh, "extern char *G_%s_names[];\n", pck);
	fprintf(fh, "\n");}

    else
       {md = sl->md;
	tl = &sl->na;

/* emit macro to define type to PDB file */
	fprintf(fh, "#define %s(_f)\t\\\n", tl->dnm);
	fprintf(fh, "   (PD_defstr_i(_f, \"%s\", \t\\\n", tl->cnm);

	a[0] = '\0';
	for (i = 0; md[i].text != NULL; i++)
	    {mbr = md[i].text;
	     if (md[i].cast != CAST_NONE)
		{p  = strstr(mbr, "MBR(");
		 *p = '\0';};

	     if (md[i].is_fnc_ptr == B_T)
	        fprintf(fh, "\t\t\"function %s\",\t\\\n", md[i].name);
	     else
	        fprintf(fh, "\t\t\"%s\",\t\\\n", trim(mbr, BOTH, " \t"));
	     
	     if (md[i].cast == CAST_TYPE)
	        vstrcat(a, BFLRG, 
			"    PD_cast(_f, \"%s\", \"%s\", \"%s\") &&\t\\\n",
			tl->cnm, md[i].name, md[i].cast_mbr);
	     else if (md[i].cast == CAST_LENGTH)
	        vstrcat(a, BFLRG, 
			"    PD_size_from(_f, \"%s\", \"%s\", \"%s\") &&\t\\\n",
			tl->cnm, md[i].name, md[i].cast_mbr);};

	if (IS_NULL(a) == FALSE)
	   {fprintf(fh, "\t\tLAST) &&\t\\\n");
	    nc = strlen(a);
	    nstrncpy(a+nc-6, 3, ")\n", 2);
	    fputs(a, fh);}
	else
	   fprintf(fh, "\t\tLAST))\n");

	fprintf(fh, "\n");

/* emit declaration of SCORE type index */
	fprintf(fh, "#define G_%s_S   G_%s_names[%d]\n",
		tl->unm, pck, 2*ni);
	fprintf(fh, "#define G_%s_P_S G_%s_names[%d]\n",
		tl->unm, pck, 2*ni+1);

	fprintf(fh, "extern int %s;\n", tl->inm);
	fprintf(fh, "\n");};

    return;}