void daemonize (const str &nm) { str pidfilebase = nm; if (!pidfilebase) pidfilebase = progname; switch (fork ()) { default: _exit (0); case -1: fatal ("fork: %m\n"); case 0: break; } if (setsid () == -1) fatal ("setsid: %m\n"); if (!builddir) { start_logger (); str path = strbuf () << PIDDIR << "/" << pidfilebase << ".pid"; struct stat sb; if (str2file (path, strbuf ("%d\n", int (getpid ())), 0444, false, &sb)) pidfiles.push_back (pidfile (path, sb)); } else { str piddir = buildtmpdir; if (!piddir) piddir = builddir; str path = strbuf () << piddir << "/" << pidfilebase << ".pid"; struct stat sb; if (str2file (path, strbuf ("%d\n", int (getpid ())), 0444, false, &sb)) pidfiles.push_back (pidfile (path, sb)); } }
/* Generate a configuration file for other processes to use */ static bool dbfe_generate_config (str path, unsigned int cachesize) { strbuf db_config; db_config << "# MIT lsd db configuration\n\n"; db_config << "set_flags DB_AUTO_COMMIT\n"; db_config << "set_flags DB_TXN_WRITE_NOSYNC\n"; // clean up old log files not available in old versions #if ((DB_VERSION_MAJOR >= 4) && (DB_VERSION_MINOR >= 2)) db_config << "set_flags DB_LOG_AUTOREMOVE\n"; #endif db_config << "# create " << cachesize << " KB cache\n"; db_config << "set_cachesize 0 " << cachesize * 1024 << " 1\n"; #if 0 /* This should be the default */ char cpath[MAXPATHLEN]; getcwd(cpath, MAXPATHLEN); db_config << "set_data_dir " << cpath << "\n"; db_config << "set_lg_dir " << cpath << "\n"; db_config << "set_tmp_dir " << cpath << "\n"; #endif /* 0 */ // Write out the configuration file return str2file (path, db_config); }
//! Handles the client broadcast network info rquest //! //! @param[in] pStub a pointer to the node controller (NC) stub structure //! @param[in] pMeta a pointer to the node controller (NC) metadata structure //! @param[in] networkInfo is a string //! //! @return Always return EUCA_OK. //! int ncBroadcastNetworkInfoStub(ncStub * pStub, ncMetadata * pMeta, char *networkInfo) { char *xmlbuf = NULL, xmlpath[EUCA_MAX_PATH]; int ret = EUCA_OK, rc = 0; if (networkInfo == NULL) { LOGERROR("internal error (bad input parameters to doBroadcastNetworkInfo)\n"); return (EUCA_INVALID_ERROR); } LOGTRACE("encoded networkInfo=%s\n", networkInfo); snprintf(xmlpath, EUCA_MAX_PATH, "/tmp/global_network_info.xml"); LOGDEBUG("decoding/writing buffer to (%s)\n", xmlpath); xmlbuf = base64_dec((unsigned char *)networkInfo, strlen(networkInfo)); if (xmlbuf) { rc = str2file(xmlbuf, xmlpath, O_CREAT | O_TRUNC | O_WRONLY, 0644, FALSE); if (rc) { LOGERROR("could not write XML data to file (%s)\n", xmlpath); ret = EUCA_ERROR; } EUCA_FREE(xmlbuf); } else { LOGERROR("could not b64 decode input buffer\n"); ret = EUCA_ERROR; } return (EUCA_OK); }
//! //! For MIDONET VPC mode, all is done in this driver API. //! //! @param[in] pGni a pointer to the Global Network Information structure //! @param[in] pLni a pointer to the Local Network Information structure //! //! @return EUCANETD_RUN_NO_API or EUCANETD_RUN_ERROR_API //! //! @see //! //! @pre //! - Both pGni and pLni must not be NULL //! - The driver must be initialized prior to calling this API. //! //! @post //! //! @note //! static u32 network_driver_system_scrub(globalNetworkInfo * pGni, lni_t * pLni) { int rc = 0; u32 ret = EUCANETD_RUN_NO_API; char versionFile[EUCA_MAX_PATH]; LOGINFO("Scrubbing for '%s' network driver.\n", DRIVER_NAME()); bzero(versionFile, EUCA_MAX_PATH); // Is the driver initialized? if (!IS_INITIALIZED()) { LOGERROR("Failed to scub the system for network artifacts. Driver '%s' not initialized.\n", DRIVER_NAME()); return (ret); } // Are the global and local network view structures NULL? if (!pGni || !pLni) { LOGERROR("Failed to implement security-group artifacts for '%s' network driver. Invalid parameters provided.\n", DRIVER_NAME()); return (ret); } // if (PEER_IS_NC(eucanetdPeer)) { if (pMidoConfig) { free_mido_config(pMidoConfig); bzero(pMidoConfig, sizeof(mido_config)); } rc = initialize_mido(pMidoConfig, config->eucahome, config->flushmode, config->disable_l2_isolation, config->midoeucanetdhost, config->midogwhosts, config->midopubnw, config->midopubgwip, "169.254.0.0", "17"); if (rc) { LOGERROR("could not initialize mido config\n"); ret = EUCANETD_RUN_ERROR_API; } else { if ((rc = do_midonet_update(pGni, pMidoConfig)) != 0) { LOGERROR("could not update midonet: check log for details\n"); ret = EUCANETD_RUN_ERROR_API; } else { LOGINFO("new Eucalyptus/Midonet networking state sync: updated successfully\n"); snprintf(versionFile, EUCA_MAX_PATH, EUCALYPTUS_RUN_DIR "/global_network_info.version", config->eucahome); if (!strlen(pGni->version) || (str2file(pGni->version, versionFile, O_CREAT | O_TRUNC | O_WRONLY, 0644, FALSE) != EUCA_OK) ) { LOGWARN("failed to populate GNI version file '%s': check permissions and disk capacity\n", versionFile); } } } // } // return (EUCANETD_RUN_NO_API); return (ret); }
int f_put (char **vec) { int append; #ifdef BRIDGE int result; char *dst; #else int sglobbed; char *bp, *dst, **gp, **src; char *freedst = NULL, buffer[BUFSIZ]; #endif append = strcmp (*vec, "append") == 0; if (*++vec == NULL) { #ifdef BRIDGE return NOTOK; #else if (getftamline ("source: ", buffer) == NOTOK || str2vec (buffer, vec) < 1) return OK; dst = NULL; #endif } else { #ifdef BRIDGE dst = *vec; #else char **ap; for (ap = vec; *ap; ap++) continue; if (--ap != vec) dst = *ap, *ap = NULL; else dst = NULL; #endif } #ifndef BRIDGE if (!(src = xglob (vec, 0))) return OK; sglobbed = xglobbed; if (dst == NULL) { if (getftamline ("destination: ", buffer) == NOTOK) { blkfree (src); return OK; } switch (str2vec (buffer, vec)) { case 0: break; case 1: dst = *vec; break; default: advise (NULLCP, "too many destinations"); goto out; } } if (dst && !(dst = freedst = xglob1val (dst, 0))) goto out; if (src[1] == NULL) { if (interrupted) goto out; if (dst == NULL) { switch (realstore) { case RFS_UNIX: if (dst = rindex (*src, '/')) dst++; if (dst == NULL || *dst == NULL) dst = *src; break; default: dst = *src; break; } dst = str2file (dst); ask_it: ; if (query) switch (ask ("%s %s %s", append ? "append" : "put", *src, dst)) { case NOTOK: goto out; case OK: default: break; case DONE: goto out; } } else switch (realstore) { case RFS_UNIX: if (isdir (dst, NULLCP, 1) == NOTOK) break; #ifdef apollo if (*dst == '/') sprintf (bp = buffer, "%s", dst); else #endif sprintf (bp = buffer, "%s/", dst); bp += strlen (bp); if (dst = rindex (*src, '/')) dst++; if (dst == NULL || *dst == NULL) dst = *src; strcpy (bp, dst); dst = buffer; goto ask_it; default: break; } dst = str2file (dst); put (*src, dst, append); goto out; } switch (realstore) { case RFS_UNKNOWN: advise (NULLCP, "%s", rs_unknown); goto out; case RFS_UNIX: if (dst) #ifdef apollo if (*(bp = str2file (dst)) == '/') { strcpy (buffer, bp); bp = buffer; } else #endif sprintf (bp = buffer, "%s/", str2file (dst)); else if (rcwd) sprintf (bp = buffer, "%s", str2file ("")); else strcpy (bp = buffer, "./"); bp += strlen (bp); break; default: advise (NULLCP, "%s", rs_support); goto out; } if (isdir (str2file (buffer), NULLCP, 0) == NOTOK) goto out; for (gp = src; *gp && !interrupted; gp++) { switch (realstore) { case RFS_UNIX: if (dst = rindex (*gp, '/')) dst++; if (dst == NULL || *dst == NULL) dst = *gp; break; default: dst = *gp; break; } strcpy (bp, dst); dst = str2file (buffer); if (sglobbed) { if (query) switch (ask ("%s %s %s", append ? "append" : "put", *gp, dst)) { case NOTOK: continue; case OK: default: break; case DONE: goto out; } else advise (NULLCP, "%s %s %s", append ? "append" : "put", *gp, dst); } put (*gp, dst, append); if (ftamfd == NOTOK) break; } out: ; blkfree (src); if (freedst) free (freedst); return OK; #else result = put (dst, append); return result; #endif }