mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-08 20:51:26 +00:00
util: process: use VIR_AUTOPTR for aggregate types
By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar <skrtbhtngr@gmail.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
ce814ed392
commit
c3a2e274c7
@ -971,17 +971,16 @@ int virProcessGetStartTime(pid_t pid,
|
|||||||
unsigned long long *timestamp)
|
unsigned long long *timestamp)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
int ret = -1;
|
|
||||||
int len;
|
int len;
|
||||||
char **tokens = NULL;
|
|
||||||
VIR_AUTOFREE(char *) filename = NULL;
|
VIR_AUTOFREE(char *) filename = NULL;
|
||||||
VIR_AUTOFREE(char *) buf = NULL;
|
VIR_AUTOFREE(char *) buf = NULL;
|
||||||
|
VIR_AUTOPTR(virString) tokens = NULL;
|
||||||
|
|
||||||
if (virAsprintf(&filename, "/proc/%llu/stat", (long long) pid) < 0)
|
if (virAsprintf(&filename, "/proc/%llu/stat", (long long) pid) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if ((len = virFileReadAll(filename, 1024, &buf)) < 0)
|
if ((len = virFileReadAll(filename, 1024, &buf)) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
/* start time is the token at index 19 after the '(process name)' entry - since only this
|
/* start time is the token at index 19 after the '(process name)' entry - since only this
|
||||||
* field can contain the ')' character, search backwards for this to avoid malicious
|
* field can contain the ')' character, search backwards for this to avoid malicious
|
||||||
@ -992,14 +991,14 @@ int virProcessGetStartTime(pid_t pid,
|
|||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Cannot find start time in %s"),
|
_("Cannot find start time in %s"),
|
||||||
filename);
|
filename);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
tmp += 2; /* skip ') ' */
|
tmp += 2; /* skip ') ' */
|
||||||
if ((tmp - buf) >= len) {
|
if ((tmp - buf) >= len) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Cannot find start time in %s"),
|
_("Cannot find start time in %s"),
|
||||||
filename);
|
filename);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
tokens = virStringSplit(tmp, " ", 0);
|
tokens = virStringSplit(tmp, " ", 0);
|
||||||
@ -1008,7 +1007,7 @@ int virProcessGetStartTime(pid_t pid,
|
|||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Cannot find start time in %s"),
|
_("Cannot find start time in %s"),
|
||||||
filename);
|
filename);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virStrToLong_ull(tokens[19],
|
if (virStrToLong_ull(tokens[19],
|
||||||
@ -1018,14 +1017,10 @@ int virProcessGetStartTime(pid_t pid,
|
|||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Cannot parse start time %s in %s"),
|
_("Cannot parse start time %s in %s"),
|
||||||
tokens[19], filename);
|
tokens[19], filename);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virStringListFree(tokens);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||||
int virProcessGetStartTime(pid_t pid,
|
int virProcessGetStartTime(pid_t pid,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user