- fp = fopen(AGENT_INFO_FILE, "w");
- if(!fp)
- {
- merror(FOPEN_ERROR, __local_name, AGENT_INFO_FILE);
- return(0);
+ debug2("%s: calling os_read_agent_profile().", __local_name);
+
+ if (isChroot()) {
+ fp = fopen(AGENT_INFO_FILE, "r");
+ } else {
+ fp = fopen(AGENT_INFO_FILEP, "r");
+ }
+
+ if (!fp) {
+ debug2("%s: Failed to open file. Errno=%d.", __local_name, errno);
+ merror(FOPEN_ERROR, __local_name, AGENT_INFO_FILE, errno, strerror(errno));
+ return (NULL);
+ }
+
+ buf[1024] = '\0';
+
+ /* Get profile */
+ if (fgets(buf, 1024, fp) && fgets(buf, 1024, fp) &&
+ fgets(buf, 1024, fp) && fgets(buf, 1024, fp)) {
+ char *ret = NULL;
+
+ /* Trim the /n and/or /r at the end of the string */
+ os_trimcrlf(buf);
+
+ os_strdup(buf, ret);
+ debug2("%s: os_read_agent_profile() = [%s]", __local_name, ret);
+
+ fclose(fp);
+
+ return (ret);