예제 #1
0
static char *mkCommonWhere(struct genomeInfo *genome, struct sqlConnection *conn,
                           boolean inclStatus)
/* Get the common clause.  This is the where clause that selects GroupVersions
 * and CcdsUids that are currently selected by organism, build, and optionally status
 * values. WARNING: static return. */
{
static char clause[1025];
safef(clause, sizeof(clause),
      "((Groups.tax_id = %d) "
      "AND (GroupVersions.group_uid = Groups.group_uid) "
      "AND (GroupVersions.build_uid = %d) "
      "AND (CcdsUids.group_uid = Groups.group_uid) ",
      genome->taxonId, genome->ccdsBuildId);

if (inclStatus)
    {
    char clause2[1025];
    safef(clause2, sizeof(clause2),
          "AND (CcdsStatusVals.ccds_status_val_uid = GroupVersions.ccds_status_val_uid) "
          "AND (CcdsStatusVals.ccds_status in (%s)) ",
          mkStatusValSet(conn));
    safecat(clause, sizeof(clause), clause2);
    }
safecat(clause, sizeof(clause), ")");
return clause;
}
예제 #2
0
파일: virusClick.c 프로젝트: bowhan/kent
static void h1n1MkChimeraxTrashFullUrl(struct tempName *tmpPdb, char *fullUrl, int fullUrlSize)
/* generate full URL for a chimerax file decompressed to trash */
{
// FIXME: this is not generate (URL generation will not work on all web servers).
// if this is kept, should address this.
char *serverName = getenv("SERVER_NAME");
char *serverPort = getenv("SERVER_PORT");
char *scriptName = getenv("SCRIPT_NAME");
if ((serverName != NULL) && (serverPort != NULL) && (scriptName != NULL))
    {
    // remote url
    safef(fullUrl, fullUrlSize, "http://%s", serverName);
    if (!sameString(serverPort, "80"))
        {
        safecat(fullUrl, fullUrlSize, ":");
        safecat(fullUrl, fullUrlSize, serverPort);
        }
    safecat(fullUrl, fullUrlSize, scriptName);
    char *p = strrchr(fullUrl, '/');
    if (p != NULL)
        *++p = '\0';  // drop cgi name, keeping directory
    safecat(fullUrl, fullUrlSize, tmpPdb->forHtml);
    }
else
    {
    // local url
    safef(fullUrl, fullUrlSize, "file:///%s/%s", getCurrentDir(), tmpPdb->forHtml);
    }
}
예제 #3
0
char *reverseComplementSlashSeparated(char *alleleStr)
/* Given a slash-separated series of sequences (a common representation of variant alleles),
 * returns a slash-sep series with the reverse complement of each sequence (if it is a
 * nucleotide sequence).
 * Special behavior to support dbSNP's variant allele conventions:
 * 1. Reverse the order of sequences (to maintain alphabetical ordering).
 * 2. If alleleStr begins with "-/", then after reversing, move "-/" back to the beginning. */
{
int len = strlen(alleleStr);
char choppyCopy[len+1];
safecpy(choppyCopy, sizeof(choppyCopy), alleleStr);
char *alleles[len];
int alCount = chopByChar(choppyCopy, '/', alleles, ArraySize(alleles));
char *outStr = needMem(len+1);
int i;
for (i = alCount-1;  i >= 0;  i--)
    {
    char *allele = alleles[i];
    int alLen = strlen(allele);
    if (isAllNt(allele, alLen))
        reverseComplement(allele, alLen);
    if (i != alCount-1)
        safecat(outStr, len+1, "/");
    safecat(outStr, len+1, allele);
    }
if (startsWith("-/", alleleStr))
    {
    // Keep "-/" at the beginning:
    memmove(outStr+2, outStr, len-2);
    outStr[0] = '-';
    outStr[1] = '/';
    }
return outStr;
}
예제 #4
0
파일: virusClick.c 프로젝트: bowhan/kent
static void tempNameFromPrefix(struct tempName *name, struct tempName *prefix, char *suffix)
/* build a tempName based on an existing tempName and a suffix */
{
safecpy(name->forCgi, sizeof(name->forCgi), prefix->forCgi);
safecat(name->forCgi, sizeof(name->forCgi), suffix);
safecpy(name->forHtml, sizeof(name->forHtml), prefix->forHtml);
safecat(name->forHtml, sizeof(name->forHtml), suffix);
}
예제 #5
0
char *lsSnpPdbGetUrlPdbSnp(char *pdbId, char *snpId)
/* get LS-SNP/PDB URL for a particular PDB and/or SNP.  One or the two
 * ids maybe null */
{
char url[256], sep='?';
safecpy(url, sizeof(url), "http://ls-snp.icm.jhu.edu/ls-snp-pdb/inquire");
if (pdbId != NULL)
    {
    safecat(url, sizeof(url), fmtParam(sep, "pdbId", pdbId));
    sep = '&';
    }
if (snpId != NULL)
    safecat(url, sizeof(url), fmtParam(sep, "snpId", snpId));
return cloneString(url);
}
예제 #6
0
static void printHeaderColumns(struct annoFormatTab *self, struct annoStreamer *source,
                               boolean isFirst)
/* Print names of included columns from this source. */
{
FILE *f = self->f;
char *sourceName = source->name;
boolean isAvg = isWiggle(source->asObj->columnList) && doAvg;
struct asColumn *col;
int i;
for (col = source->asObj->columnList, i = 0;  col != NULL;  col = col->next, i++)
    {
    if (columnIsIncluded(self, sourceName, col->name))
        {
        if (isFirst)
            {
            fputc('#', f);
            isFirst = FALSE;
            }
        else
            fputc('\t', f);
        char fullName[PATH_LEN];
        makeFullColumnName(fullName, sizeof(fullName), sourceName, col->name);
        if (isAvg && sameString(col->name, "value"))
            safecat(fullName, sizeof(fullName), "Average");
        fputs(fullName, f);
        }
    }
}
예제 #7
0
static char *mkCommonFrom(boolean inclStatus)
/* Get common FROM clause. WARNING: static return. */
{
static char clause[257];
safecpy(clause, sizeof(clause),
        "Groups, "
        "GroupVersions, "
        "CcdsUids");
if (inclStatus)
    safecat(clause, sizeof(clause), ", CcdsStatusVals");
return clause;
}
예제 #8
0
static struct hashEl *mkDefault(struct prefixElems *dbElems,
                                struct hashEl *defEl)
/* generate a database-specific value from a default */
{
char name[128];
safecpy(name, sizeof(name), dbElems->prefix);
safecat(name, sizeof(name), strchr(defEl->name, '.'));

struct hashEl *dbDefEl;
AllocVar(dbDefEl);
dbDefEl->name = cloneString(name);
dbDefEl->val = defEl->val;
return dbDefEl;
}
예제 #9
0
파일: vcfTrack.c 프로젝트: maximilianh/kent
static struct pgSnp *vcfFileToPgSnp(struct vcfFile *vcff, struct trackDb *tdb)
/* Convert vcff's records to pgSnp; don't free vcff until you're done with pgSnp
 * because it contains pointers into vcff's records' chrom. */
{
struct pgSnp *pgsList = NULL;
struct vcfRecord *rec;
int maxLen = 33;
int maxAlCount = 5;
for (rec = vcff->records;  rec != NULL;  rec = rec->next)
    {
    struct pgSnpVcfStartEnd *psvs = needMem(sizeof(*psvs));
    psvs->vcfStart = vcfRecordTrimIndelLeftBase(rec);
    psvs->vcfEnd = vcfRecordTrimAllelesRight(rec);
    struct pgSnp *pgs = pgSnpFromVcfRecord(rec);
    memcpy(&(psvs->pgs), pgs, sizeof(*pgs));
    pgs = (struct pgSnp *)psvs; // leak mem
    // Insertion sequences can be quite long; abbreviate here for display.
    int len = strlen(pgs->name);
    if (len > maxLen)
	{
	int maxAlLen = (maxLen / min(rec->alleleCount, maxAlCount)) - 1;
	pgs->name[0] = '\0';
	int i;
	for (i = 0;  i < rec->alleleCount;  i++)
	    {
	    if (i > 0)
		safencat(pgs->name, len+1, "/", 1);
	    if (i >= maxAlCount)
		{
		safecat(pgs->name, len+1, "...");
		pgs->alleleCount = maxAlCount;
		break;
		}
	    if (strlen(rec->alleles[i]) > maxAlLen-3)
		strcpy(rec->alleles[i]+maxAlLen-3, "...");
	    safencat(pgs->name, len+1, rec->alleles[i], maxAlLen);
	    }
	}
    slAddHead(&pgsList, pgs);
    }
slReverse(&pgsList);
return pgsList;
}
예제 #10
0
static boolean matchingFilesExist(char *db, char* varName, char *val, char *replacePre, char *replaceVal)
/* Check that files specified by variable value exist */
{
char path[PATH_LEN];

if ((replacePre != NULL) && startsWith(replacePre, val))
    {
    safecpy(path, sizeof(path), replaceVal);
    safecat(path, sizeof(path), val+strlen(replacePre));
    }
else
    safecpy(path, sizeof(path), val);

char *name = strrchr(path, '/');
if (name == NULL)
    errAbort("must have absolute path: %s.%s = %s", db, varName, val);
*name++ = '\0';
struct slName *hits = listDir(path, name);
boolean have = (hits != NULL);
slFreeList(&hits);
verbose(3, "%s.%s\t%s\t%s/%s\n", db, varName, (have ? "have" : "missing"), path, name);
return have;
}
예제 #11
0
파일: vcfTrack.c 프로젝트: maximilianh/kent
INLINE void abbrevAndHandleRC(char *abbrevAl, size_t abbrevAlSize, const char *fullAl)
/* Limit the size of displayed allele to abbrevAlSize-1 and handle reverse-complemented display. */
{
boolean fullLen = strlen(fullAl);
boolean truncating = (fullLen > abbrevAlSize-1);
if (truncating)
    {
    int truncLen = abbrevAlSize - 4;
    if (revCmplDisp)
	{
	safencpy(abbrevAl, abbrevAlSize, (fullAl + fullLen - truncLen), truncLen);
	reverseComplement(abbrevAl, truncLen);
	}
    else
	safencpy(abbrevAl, abbrevAlSize, fullAl, truncLen);
    safecat(abbrevAl, abbrevAlSize, "...");
    }
else
    {
    safecpy(abbrevAl, abbrevAlSize, fullAl);
    if (revCmplDisp)
	reverseComplement(abbrevAl, fullLen);
    }
}
예제 #12
0
void checkFilename(struct sqlConnection *conn, char *table, struct hash *allBbiNames)
{
char buffer[10 * 1024];
char fileName[10 * 1024];
char oldSymlink[10 * 1024];

verbose(2, "checking for fileName field in table %s \n", table);

// see if this is even a bbi table 
boolean bbiTable = FALSE;
struct slName *fnames = sqlFieldNames(conn, table);
if ((slCount(fnames) == 1) && (sameString(fnames->name, "fileName")))
    bbiTable = TRUE;
slFreeList(&fnames);
if (!bbiTable)
    return;

sqlSafef(buffer, sizeof buffer, "select fileName from %s limit 1", table);
if (sqlQuickQuery(conn, buffer, fileName, sizeof fileName) != NULL)
    {
    while(1)  // loop to catch .bai as well as .bam
	{


	hashAdd(allBbiNames, fileName, NULL);

	verbose(2,"got table.fileName %s\n", fileName);

	// file exists
	FILE *f = fopen(fileName, "r");
	if (f == NULL)
	    {
	    warn("fileName %s from table %s can't be opened", fileName, table);
	    return;
	    }
	else
	    fclose(f);

        // check that the filename and object base match
	char *base = strrchr(fileName, '/');
	if (base == NULL)
	    {
	    warn("fileName %s in table %s not absolute path", fileName, table);
	    return;
	    }
	else
	    {
	    base++;
	    char *dot = strchr(base, '.');
	    if (dot == NULL)
		{
		warn("fileName %s in table %s does not have suffix", fileName, table);
		return;
		}
	    else
		{
		char saveChar = *dot;
		*dot = 0;
		if (!sameString(table, base))
		    {
		    warn("fileName %s doesn't match table  %s", base, table);
		    return;
		    }
		*dot = saveChar;
		}
	    }

        // this file is really a symlink, so check its link target
	ssize_t bufRead = readlink(fileName, oldSymlink, sizeof oldSymlink);
	if (bufRead == -1)
	    {
	    errnoWarn("error reading symlink %s", fileName);
	    return;
	    }
	else
	    {		
	    oldSymlink[bufRead] = 0;  // needs termination.
	    if (!fileExists(oldSymlink))
		{
		warn("symlink target %s does not exist!", oldSymlink);
		return;
		}
	    else
		verbose(2,"got symlink %s\n", oldSymlink);
	    }

        // check that the symlink and object base match
	base = strrchr(oldSymlink, '/');
	if (base == NULL)
	    {
	    warn("symlink %s in fileName %s not absolute path",oldSymlink, fileName);
	    return;
	    }
	else
	    {
	    base++;
	    char *dot = strchr(base, '.');
	    if (dot == NULL)
		{
		warn("symlink %s in fileName %s does not have suffix", oldSymlink, fileName);
		return;
		}
	    else
		{
		char saveChar = *dot;
		*dot = 0;
		if (!sameString(table, base))
		    {
		    warn("symlink %s doesn't match table  %s", base, table);
		    return;
		    }
		*dot = saveChar;
		}
	    }

        /* Note "fileIndex" for .bai has been made obsolete
         so we'll just hard-wire in the .bai support */
	if (!endsWith(fileName, ".bam"))
	    break;
	safecat(fileName, sizeof(fileName), ".bai");
	}

    }
}
예제 #13
0
/*----------------------------------------------------------------------*/
int daf_service_delete(void)
{

    char cmd[1024];
    char msg[1024];
    char timestamp[16];
    char backup_inittab_filename[64];

#if defined AIX

    print_msg_to_console("Updating /etc/inittab entry\n");

    //--------------------------------------------------------------------------
    // remove any previous entry
    //--------------------------------------------------------------------------

    safecpy(backup_inittab_filename, "/etc/inittab.", sizeof(backup_inittab_filename));
    get_current_time_as_timestamp(timestamp, sizeof(timestamp), '.');
    safecat(backup_inittab_filename, timestamp, sizeof(backup_inittab_filename));
    sprintf(msg, "Backing up /etc/inittab in %s\n", backup_inittab_filename);
    print_msg_to_console(msg);

    if (copy_file("/etc/inittab", backup_inittab_filename) != 0)
    {
        safecpy(msg, "Backup of inittab failed: ", sizeof(msg));
        safecat(msg, cmd, sizeof(msg));
        safecat(msg, "\n", sizeof(msg));
        print_msg_to_console(msg);
        return(1);
    }

    print_msg_to_console("  Removing any previous daf service entry in /etc/inittab\n");
    safecpy(cmd, "cat /etc/inittab | grep \"daf:\"", sizeof(cmd));

    if (run_system_cmd(cmd, 1) == 0)
    {

        safecpy(cmd, "rmitab \"daf\"", sizeof(cmd));

        if (run_system_cmd_and_print_all_output(cmd) != 0)
        {
            safecpy(msg, "Removal of daf service entry in /etc/inittab failed: ", sizeof(msg));
            safecat(msg, cmd, sizeof(msg));
            safecat(msg, "\n", sizeof(msg));
            print_msg_to_console(msg);
            return(1);
        }

    }
    else
    {
        safecpy(msg, "No daf entry found in /etc/inittab so none was removed\n", sizeof(msg));
        print_msg_to_console(msg);
    }

    print_msg_to_console("/etc/inittab entry updated successfully\n");

#elif defined LINUX || defined SOLARIS || defined HPUX

    //--------------------------------------------------------------------------
    // remove any previous entry
    //--------------------------------------------------------------------------

    // This could be Debian/Ubuntu and could be before we have installed DAF so there might not
    // be a /etc/inittab file existing yet - check for this

    if (! does_file_exist("/etc/inittab"))
    {

        if (does_file_exist(DAF_DEBIAN_ETC_INIT_CONF_PATH))
        {
            safecpy(cmd, "rm " DAF_DEBIAN_ETC_INIT_CONF_PATH, sizeof(cmd));

            if (run_system_cmd(cmd, 1) != 0)
            {
                safecpy(msg, "Removal of " DAF_DEBIAN_ETC_INIT_CONF_PATH " failed\n", sizeof(msg));
                print_msg_to_console(msg);
                return(1);
            }
        }

        print_msg_to_console(DAF_DEBIAN_ETC_INIT_CONF_PATH " removed\n");

    }
    else
    {

        print_msg_to_console("Updating /etc/inittab entry\n");

        safecpy(backup_inittab_filename, "/etc/inittab.", sizeof(backup_inittab_filename));
        get_current_time_as_timestamp(timestamp, sizeof(timestamp), '.');
        safecat(backup_inittab_filename, timestamp, sizeof(backup_inittab_filename));
        sprintf(msg, "Backing up /etc/inittab in %s\n", backup_inittab_filename);
        print_msg_to_console(msg);

        if (copy_file ("/etc/inittab", backup_inittab_filename) != 0)
        {
            safecpy(msg, "Backup of inittab failed: ", sizeof(msg));
            safecat(msg, cmd, sizeof(msg));
            safecat(msg, "\n", sizeof(msg));
            print_msg_to_console(msg);
            return(1);
        }

        print_msg_to_console("  Removing any previous daf service entry in /etc/inittab\n");
        safecpy(cmd, "cat ", sizeof(cmd));
        safecat(cmd, backup_inittab_filename, sizeof(cmd));
        safecat(cmd, " | grep -v \""DAF_SERVICE_INVOCATION"\" > /etc/inittab", sizeof(cmd));

        if (run_system_cmd(cmd, 0) != 0)
        {
            safecpy(msg, "Removal of previous daf service in inittab failed: ", sizeof(msg));
            safecat(msg, cmd, sizeof(msg));
            safecat(msg, "\n", sizeof(msg));
            print_msg_to_console(msg);
            return(1);
        }

        print_msg_to_console("/etc/inittab entry updated successfully\n");
    }


#endif

    if (is_daf_service_running())
    {
        print_msg_to_console("daf daemon is running - and will now be stopped\n");

        if (stop_daf_service_running() != 0)
        {
            print_msg_to_console("Problem trying to stop daf daemon\n");
        }
    }

    return(0);

}
예제 #14
0
/*----------------------------------------------------------------------*/
int daf_service_install(char *daf_binary_path, char *argv0)
{

    char cmd[1024];
    char msg[1024];
    char daf_path[64];
    char daf_binary_to_install[64];
    char timestamp[16];
    char backup_inittab_filename[64];

    struct stat fileStat;
    char *pathname = "/etc/inittab";

    if (daf_binary_path == NULL)
    {
        if (get_current_executable_path(argv0, daf_binary_to_install, sizeof(daf_binary_to_install)) !=0)
        {
            print_msg_to_console("Problem trying to determine path of current executable\n");
            return(1);
        }
    }
    else
    {
        safecpy(daf_binary_to_install, daf_binary_path, sizeof(daf_binary_to_install));
    }

    // ensure that directories that are needed do actually exist and delelete existing profile
    // and start up script

    ensure_directory_path_exists(DAF_SERVICE_BINARY_DIR);
    ensure_directory_path_exists(DAF_SERVICE_LOG_DIR);
    delete_file(DAF_SERVICE_START_SCRIPT_PATH);
    delete_file(DAF_SERVICE_PROFILE_PATH);

    // are we trying to copy the same file onto itself, -if so then
    // do not do the copy as it it will fail
    if (strcmp(daf_binary_to_install, DAF_SERVICE_BINARY_PATH) == 0)
    {

        sprintf(msg, "Requested install image %s is identical to install destination: %s\n",
                daf_binary_to_install, DAF_SERVICE_BINARY_PATH);
        print_msg_to_console(msg);

    }
    else
    {

        if (copy_file(daf_binary_to_install, DAF_SERVICE_BINARY_PATH) != 0)
        {
            /* make sure the SETuid bit is on so that daf can assume root priviledges if it is run by a non root user */
            /* is this a security hole ?? <<<<<<<<<< */
            sprintf(msg, "Could not copy %s into installation directory at %s\n", daf_binary_to_install, DAF_SERVICE_BINARY_PATH);
            print_msg_to_console(msg);
            return(1);
        }
        else
        {
            if (chmod_file(DAF_SERVICE_BINARY_PATH, "u+s") != 0)
            {
                sprintf(msg, "Could not set setuid permission bit on %s\n", DAF_SERVICE_BINARY_PATH);
                print_msg_to_console(msg);
                return(1);
            }
        }

    }

    if (create_default_daf_service_profile() != 0)
    {
        print_msg_to_console("Could not install command profile into standard daf service directory\n");
        return(1);
    }
    else
    {
        print_msg_to_console("daf service command profile installed successfully\n");
    }


    if (create_daf_service_start_script() != 0)
    {
        print_msg_to_console("Could not install start script into standard daf service directory\n");
        return(1);
    }
    else
    {
        print_msg_to_console("daf service start script installed successfully\n");
    }

    //--------------------------------------------------------------------------
    //
    //--------------------------------------------------------------------------

    safecpy(daf_path, DAF_SERVICE_BINARY_PATH, sizeof(daf_path));

    if (is_daf_service_running())
    {
        print_msg_to_console("daf daemon is running - and will now be stopped\n");

        if (stop_daf_service_running() != 0)
        {
            print_msg_to_console("Problem trying to stop daf daemon\n");
        }
    }

    print_msg_to_console("Updating /etc/inittab entry\n");

#if defined AIX

    //--------------------------------------------------------------------------
    // remove any previous entry
    //--------------------------------------------------------------------------

    print_msg_to_console("Removing any previous daf service entry in /etc/inittab\n");
    safecpy(cmd, "cat /etc/inittab | grep \"daf:\"", sizeof(cmd));

    if (run_system_cmd(cmd, 1) == 0)
    {

        safecpy(cmd, "rmitab \"daf\"", sizeof(cmd));

        if (run_system_cmd_and_print_all_output(cmd) != 0)
        {
            safecpy(msg, "Removal of daf service entry in /etc/inittab failed: ", sizeof(msg));
            safecat(msg, cmd, sizeof(msg));
            safecat(msg, "\n", sizeof(msg));
            print_msg_to_console(msg);
            return(1);
        }
    }

    //--------------------------------------------------------------------------
    // Add daf daemon to /etc/inittab
    //--------------------------------------------------------------------------

    safecpy(backup_inittab_filename, "/etc/inittab.", sizeof(backup_inittab_filename));
    get_current_time_as_timestamp(timestamp, sizeof(timestamp), '.');
    safecat(backup_inittab_filename, timestamp, sizeof(backup_inittab_filename));
    sprintf(msg, "Backing up /etc/inittab in %s\n", backup_inittab_filename);
    print_msg_to_console(msg);

    if (copy_file("/etc/inittab", backup_inittab_filename) != 0)
    {
        safecpy(msg, "Backup of inittab failed: ", sizeof(msg));
        safecat(msg, "Could not copy /etc/inittab to %s", backup_inittabl_filename, sizeof(msg));
        print_msg_to_console(msg);
        return(1);
    }

    print_msg_to_console("Adding daf service entry to /etc/inittab\n");

    safecpy(cmd, "mkitab \"daf:2:once:", sizeof(cmd));
    safecat(cmd, DAF_SERVICE_INVOCATION, sizeof(cmd));
    safecat(cmd, " >/dev/null 2>&1", sizeof(cmd));
    safecat(cmd, "\"", sizeof(cmd));

    if (run_system_cmd_and_print_all_output(cmd) != 0)
    {
        safecpy(msg, "Update of inittab failed: ", sizeof(msg));
        safecat(msg, cmd, sizeof(msg));
        safecat(msg, "\n", sizeof(msg));
        print_msg_to_console(msg);
        return(1);
    }

#elif defined LINUX || defined SOLARIS || defined HPUX

    //--------------------------------------------------------------------------
    // Add daf daemon to /etc/inittab
    // First check to see if /etc/inittab exists - if it does not this may be
    // Debian or Ubuntu in which case we must create an empty file
    // (Debian/Ubuntu use the Startup mechanism instead of /etc/inittab but
    // still support the old /etc/inittab file it is present
    // see for instance:  http://upstart.ubuntu.com/cookbook/
    //--------------------------------------------------------------------------

    if (!does_file_exist("/etc/inittab"))
    {
        sprintf(msg, "/etc/inittab did not exist - assuming Debian/Ubuntu - so creating /etc/init entry\n");
        print_msg_to_console(msg);
        create_etc_init_conf();
        return(0);
    }

    if (stat(pathname, &fileStat) < 0)
    {

        sprintf(msg, "stat(%s) failed - it seems %s is missing !!!!!!!!!!!!!!!!!!!!! \n", pathname, pathname );
        print_msg_to_console(msg);
        return(1);
    }

    // Later versions of Redhat etc do not use /etc/inittab (but will still honour it if exists - so if the file is empty,
    // we just put a single comment line into so that later code that updates the /etc/inittab file will work
    if (fileStat.st_size == 0)
    {

        if (run_system_cmd("cat '* just a comment' >>/etc/inittab", 0) != 0)
        {
            safecpy(msg, "cat \"* just a comment\" >>/etc/inittab failed\n", sizeof(msg));
            print_msg_to_console(msg);
            return(1);
        }
    }

    //--------------------------------------------------------------------------
    // remove any previous entry, making sure we backup /etc/inittab
    //--------------------------------------------------------------------------

    safecpy(backup_inittab_filename, "/etc/inittab.", sizeof(backup_inittab_filename));
    get_current_time_as_timestamp(timestamp, sizeof(timestamp), '.');
    safecat(backup_inittab_filename, timestamp, sizeof(backup_inittab_filename));
    sprintf(msg, "Backing up /etc/inittab in %s\n", backup_inittab_filename);
    print_msg_to_console(msg);
    print_msg_to_console("Removing any previous daf service entry in /etc/inittab\n");

    if (copy_file("/etc/inittab", backup_inittab_filename) != 0)
    {
        snprintf(msg, sizeof(msg), "Copy of /etc/inittab to %s failed\n", backup_inittab_filename);
        print_msg_to_console(msg);
        return(1);
    }

    safecpy(cmd, "cat ", sizeof(cmd));
    safecat(cmd, backup_inittab_filename, sizeof(cmd));
    safecat(cmd, " | grep -v \""DAF_SERVICE_INVOCATION"\" > /etc/inittab", sizeof(cmd));

    if (run_system_cmd(cmd, 0) != 0)
    {
        safecpy(msg, "Removal of previous daf service in inittab failed: ", sizeof(msg));
        safecat(msg, cmd, sizeof(msg));
        safecat(msg, "\n", sizeof(msg));
        print_msg_to_console(msg);
        return(1);
    }

    safecpy(cmd, "cat ", sizeof(cmd));
    safecat(cmd, backup_inittab_filename, sizeof(cmd));
    safecat(cmd, " | grep -v \""DAF_SERVICE_INVOCATION"\" > /etc/inittab", sizeof(cmd));

    if (run_system_cmd(cmd, 0) != 0)
    {
        safecpy(msg, "Removal of previous daf service in inittab failed: ", sizeof(msg));
        safecat(msg, cmd, sizeof(msg));
        safecat(msg, "\n", sizeof(msg));
        print_msg_to_console(msg);
        return(1);
    }

    //--------------------------------------------------------------------------
    // Add daf daemon to /etc/inittab
    //--------------------------------------------------------------------------

    print_msg_to_console("Adding daf service entry to /etc/inittab\n");

    safecpy(cmd, "echo \"daf:345:once:", sizeof(msg));
    safecat(cmd, DAF_SERVICE_INVOCATION, sizeof(cmd));
    safecat(cmd, " \" 2>/dev/null >>/etc/inittab", sizeof(cmd));

    if (run_system_cmd(cmd, 0) != 0)
    {
        safecpy(msg, "Adding daf service entry to /etc/inittab: ", sizeof(msg));
        safecat(msg, cmd, sizeof(msg));
        safecat(msg, "\n", sizeof(msg));
        print_msg_to_console(msg);
        return(1);
    }

#endif

    print_msg_to_console("/etc/inittab entry updated successfully\n");

    return(0);

}
예제 #15
0
/*----------------------------------------------------------------------*/
int get_current_executable_path(char *executable, char *path, int max_path_length)
{

    char cwdpath[64];
#if defined AIX
    char cmd[256];
    char msg[1024];
#elif defined LINUX
    char cmd[256];
    char msg[1024];
#elif defined SOLARIS
    const char *pexecpath;
#elif defined HPUX
    char *pexecpath;
#elif defined WIN32

#endif

    if (strlen(executable) == 0 )
    {
        safecpy(path, "notknown", max_path_length);
        return(1);
    }

    if (executable[0] == '/')
    {
        safecpy(path, executable, max_path_length);
        return(0);
    }

    if (strlen(executable) > 1)
    {
        if ((executable[0] == '.') && (executable[1] == '/'))
        {
            getcwd(cwdpath, sizeof(cwdpath));
            safecpy(path, cwdpath, max_path_length);
            safecat(path, &executable[1], max_path_length);
            return(0);
        }
    }

#if defined AIX

    sprintf(cmd, "which %s", executable);

    if (run_system_cmd_and_capture_single_line_output(cmd, path , max_path_length))
    {
        sprintf(msg, "command to find path of current executable: %s failed\n", cmd);
        print_msg_to_console(msg);
        return(1);
    }

#elif defined LINUX

    //  readlink("/proc/self/exe", path, max_path_length);

    sprintf(cmd, "which %s", executable);

    if (run_system_cmd_and_capture_single_line_output(cmd, path , max_path_length))
    {
        sprintf(msg, "command to find path of current executable: %s failed\n", cmd);
        print_msg_to_console(msg);
        return(1);
    }

#elif defined SOLARIS

    getcwd(cwdpath, sizeof(cwdpath));
    pexecpath = getexecname();

    safecpy(path, pexecpath, max_path_length);

    if (path[0] != '/')
    {
        safecpy(path, cwdpath, max_path_length);
        safecat(path, pexecpath, max_path_length);
    }

#elif defined HPUX

    pexecpath = pathfind(getenv("PATH"), executable, "x");
    safecpy(path, pexecpath, max_path_length);

#elif defined WIN32 || defined NETWARE

    safecpy(path, "not done yet", max_path_length);

#endif

    chomp(path);
    return(0);

}