/* * Adds an entry to a child-map. * * @retval 0 Success * @retval 1 Usage error. \c log_start() called. * @retval 2 O/S failure. \c log_start() called. */ int cm_add_string( ChildMap* const map, /**< [in/out] Pointer to the child-map */ const pid_t pid, /**< [in] Process ID of the child. * Must not already exist in map. */ const char* const command) /**< [in] Command-line of the child. * Defensively copied. */ { int status; if (NULL == map) { LOG_START0("Null map argument"); status = 1; } else if (NULL == command) { LOG_START0("Null command argument"); status = 1; } else { status = cm_contains(map, pid); if (0 == status) { Entry* const entry = (Entry*)malloc(sizeof(Entry)); if (NULL == entry) { LOG_SERROR0("Couldn't allocate new entry"); status = 2; } else { entry->command = strdup(command); if (NULL == entry->command) { LOG_SERROR0("Couldn't duplicate command-line"); status = 2; } else { entry->pid = pid; if (NULL == tsearch(entry, &map->root, compare)) { LOG_SERROR0("Couldn't add entry to map"); status = 2; } else { map->count++; status = 0; } if (0 != status) free(entry->command); } /* "entry->command" allocated */ if (0 != status) free(entry); } /* "entry" allocated */ } /* "pid" not in map */ } /* valid arguments */ return status; }
/** * Removes an entry from a child-map. * * @retval 0 Success. The entry was removed. * @retval 1 Usage error. \c log_start() called. * @retval 2 The entry wasn't in the map. */ int cm_remove( ChildMap* const map, /**< [in/out] Pointer to the child-map */ const pid_t pid) /**< [in] Process ID of the entry to be removed */ { int status; if (NULL == map) { LOG_START0("NULL map argument"); status = 1; } else { if (NULL != map->root) { Entry template; Entry* const* node;
/** * Returns the pathname of the memory-file corresponding to a server and a * multicast group. This function is reentrant. * * @param[in] servAddr The address of the server associated with the multicast * group. * @param[in] feedtype Feedtype of multicast group. * @retval NULL Failure. `log_start()` called. * @return The path of the corresponding memory-file. The caller * should free when it's no longer needed. */ static char* getSessionPath( const ServiceAddr* const servAddr, const feedtypet feedtype) { char* path; char ftBuf[256]; if (sprint_feedtypet(ftBuf, sizeof(ftBuf), feedtype) < 0) { LOG_START0("sprint_feedtypet() failure"); path = NULL; } else { path = ldm_format(256, "%s/%s_%s.yaml", getLdmLogDir(), servAddr->inetId, ftBuf); } return path; }