- ret = fprintf(fp, "%d\n", (int) pid);
- if (ret < 0) {
- PERROR("fprintf pid file");
- goto error;
- }
-
- if (fclose(fp)) {
- PERROR("fclose");
- }
- DBG("Pid %d written in file %s", (int) pid, filepath);
- ret = 0;
-error:
- return ret;
-}
-
-/*
- * Create lock file to the given path and filename.
- * Returns the associated file descriptor, -1 on error.
- */
-int utils_create_lock_file(const char *filepath)
-{
- int ret;
- int fd;
- struct flock lock;
-
- LTTNG_ASSERT(filepath);
+ fp = fdopen(fd, "w");
+ if (fp == nullptr) {
+ PERROR("fdopen file %s", filepath);
+ ret = -1;
+ if (close(fd)) {
+ PERROR("Failed to close `%s` file descriptor while handling fdopen error",
+ filepath);
+ }