_E("Couldn't allocate memory for crash_crash_path: %m\n");
return 0;
}
- snprintf(crash_crash_path, tmp_len, "%s%s", crash_root_path, CRASH_PATH_SUBDIR);
+ snprintf(crash_crash_path, tmp_len + 1, "%s%s", crash_root_path, CRASH_PATH_SUBDIR);
tmp_len = strlen(crash_root_path) + strlen(CRASH_TEMP_SUBDIR);
crash_temp_path = (char*)malloc(tmp_len + 1);
_E("Couldn't allocate memory for crash_temp_path: %m\n");
return 0;
}
- snprintf(crash_temp_path, tmp_len, "%s%s", crash_root_path, CRASH_TEMP_SUBDIR);
+ snprintf(crash_temp_path, tmp_len + 1, "%s%s", crash_root_path, CRASH_TEMP_SUBDIR);
return 1;
}
g_variant_unref(reply);
if (parameters)
g_variant_unref(parameters);
+
+ g_object_unref(conn);
}
static int dump_system_state(const struct crash_info *cinfo)
dpercent = get_disk_used_percent("/opt");
if (90 < dpercent) {
- fprintf_fd(out_fd, "\n==== System disk space usage detail - %d\% (/bin/du -ah /opt)\n", dpercent);
+ fprintf_fd(out_fd, "\n==== System disk space usage detail - %d%% (/bin/du -ah /opt)\n", dpercent);
char *du_args[] = {"/bin/du", "-ah", "/opt", "--exclude=/opt/usr", NULL};
ret = run_command_write_fd_timeout(du_args[0], du_args, NULL, out_fd, NULL, 0, TIMEOUT_DEFAULT);
if (ret < 0)
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
+#include <sys/sendfile.h>
#include <dirent.h>
#include <fcntl.h>
#include <stdarg.h>
}
}
-/* WARNING : formatted string buffer is limited to 1024 byte */
-int fprintf_fd(int fd, const char *fmt, ...)
-{
- int n;
- int ret;
- char buff[1024];
- va_list args;
-
- va_start(args, fmt);
- n = vsnprintf(buff, 1024 - 1, fmt, args);
- ret = write(fd, buff, n);
- va_end(args);
- return ret;
-}
-
int file_exist(const char *file)
{
FILE *fp;
while (len) {
count = write(fd, buf, len);
if (count < 0) {
+ if (errno == EINTR)
+ continue;
if (total)
return total;
return count;
return total;
}
+static int copy_bytes(int dfd, int sfd)
+{
+ int res = 1;
+ ssize_t bytes_sent;
+ do
+ bytes_sent = sendfile(dfd, sfd, NULL, PIPE_BUF);
+ while (bytes_sent > 0);
+
+ if (bytes_sent == -1) {
+ _E("sendfile() error: %m\n");
+ res = -1;
+ }
+ return res;
+}
+
int copy_file(char *src, char *dst)
{
+ int res;
int sfd;
int dfd;
- char buf[PIPE_BUF];
if (!src || !dst) {
_E("Invalid argument\n");
_SE("Failed to open (%s)\n", dst);
return -1;
}
- for (;;) {
- int ret = read(sfd, buf, sizeof(buf));
- if (ret > 0)
- ret = write_fd(dfd, buf, ret);
- if (ret <= 0)
- break;
- }
+
+ res = copy_bytes(dfd, sfd);
+
close(sfd);
close(dfd);
- return 1;
+ return res;
}
int cat_file(char *src, char *dst)
{
+ int res;
int sfd;
int dfd;
- char buf[PIPE_BUF];
if (!src || !dst) {
_E("Invalid argument\n");
_SE("Failed to open (%s)\n", dst);
return -1;
}
- for (;;) {
- int ret = read(sfd, buf, sizeof(buf));
- if (ret > 0)
- ret = write_fd(dfd, buf, ret);
- if (ret <= 0)
- break;
- }
+
+ res = copy_bytes(dfd, sfd);
+
close(sfd);
close(dfd);
- return 1;
+ return res;
}
int move_file(char *src, char *dst)
int dump_file_write_fd(char *src, int dfd)
{
+ int res;
int sfd;
- char buf[PIPE_BUF];
if (!src) {
_E("Invalid argument\n");
_SE("Failed to open (%s)\n", src);
return -1;
}
- for (;;) {
- int ret = read(sfd, buf, sizeof(buf));
- if (ret > 0)
- ret = write_fd(dfd, buf, ret);
- if (ret <= 0)
- break;
- }
+
+ res = copy_bytes(dfd, sfd);
+
close(sfd);
- return 1;
+ return res;
}
static int run_command(char *path, char *args[], char *env[], int fd[])
int wait_system_command(int pid);
-int fprintf_fd(int fd, const char *fmt, ...);
+#define fprintf_fd(fd, fmt, ...) dprintf(fd, fmt, ##__VA_ARGS__)
int write_fd(int fd, const void *buf, int len);
return (num == 0 && cs == str) ? NULL : str;
}
-/* WARNING : formatted string buffer is limited to 1024 byte */
-int fprintf_fd(int fd, const char *fmt, ...)
-{
- int n, ret;
- char buff[1024];
- va_list args;
-
- va_start(args, fmt);
- n = vsnprintf(buff, 1024 - 1, fmt, args);
- ret = write(fd, buff, n);
- if (ret < 0)
- fprintf(stderr, "write failed\n");
- va_end(args);
- return n;
-}
-
char *remove_path(const char *cmd)
{
char *cp;
char *fgets_fd(char *str, int len, int fd);
-/* WARNING : formatted string buffer is limited to 1024 byte */
-int fprintf_fd(int fd, const char *fmt, ...);
+#define fprintf_fd(fd, fmt, ...) dprintf(fd, fmt, ##__VA_ARGS__)
char *remove_path(const char *cmd);