Lines Matching +full:set +full:- +full:content

2  * QEMU Guest Agent POSIX-specific command implementations
11 * See the COPYING file in the top-level directory.
19 #include "qga-qapi-commands.h"
21 #include "qemu/host-utils.h"
25 #include "commands-common.h"
58 if (rpid == -1) { in ga_wait_child()
74 fd[1] = -1; in ga_pipe_read_str()
80 len = -errno; in ga_pipe_read_str()
90 fd[0] = -1; in ga_pipe_read_str()
105 int retcode = -1; in ga_run_command()
106 int infd[2] = { -1, -1 }; in ga_run_command()
107 int outfd[2] = { -1, -1 }; in ga_run_command()
152 infd[0] = -1; in ga_run_command()
160 infd[1] = -1; in ga_run_command()
165 error_setg_errno(errp, -len, "%s: cannot read from stdout/stderr pipe", in ga_run_command()
200 if (infd[0] != -1) { in ga_run_command()
203 if (infd[1] != -1) { in ga_run_command()
206 if (outfd[0] != -1) { in ga_run_command()
209 if (outfd[1] != -1) { in ga_run_command()
222 const char *powerdown_flag = "-i5"; in qmp_guest_shutdown()
223 const char *halt_flag = "-i0"; in qmp_guest_shutdown()
224 const char *reboot_flag = "-i6"; in qmp_guest_shutdown()
226 const char *powerdown_flag = "-p"; in qmp_guest_shutdown()
227 const char *halt_flag = "-h"; in qmp_guest_shutdown()
228 const char *reboot_flag = "-r"; in qmp_guest_shutdown()
230 const char *powerdown_flag = "-P"; in qmp_guest_shutdown()
231 const char *halt_flag = "-H"; in qmp_guest_shutdown()
232 const char *reboot_flag = "-r"; in qmp_guest_shutdown()
235 slog("guest-shutdown called, mode: %s", mode); in qmp_guest_shutdown()
250 shutdown_flag, "-g0", "-y", in qmp_guest_shutdown()
254 "-h", shutdown_flag, "+0", in qmp_guest_shutdown()
272 const char *argv[] = {"/sbin/hwclock", has_time ? "-w" : "-s", NULL}; in qmp_guest_set_time()
274 /* If user has passed a time, validate and set it. */ in qmp_guest_set_time()
278 /* year-2038 will overflow in case time_t is 32bit */ in qmp_guest_set_time()
294 error_setg_errno(errp, errno, "Failed to set time to guest"); in qmp_guest_set_time()
299 /* Now, if user has passed a time to set and the system time is set, we in qmp_guest_set_time()
301 * passed, user is requesting the opposite: set the system time from the in qmp_guest_set_time()
303 ga_run_command(argv, NULL, "set hardware clock to system time", in qmp_guest_set_time()
337 return -1; in guest_file_handle_add()
341 gfh->id = handle; in guest_file_handle_add()
342 gfh->fh = fh; in guest_file_handle_add()
354 if (gfh->id == id) { in guest_file_handle_find()
407 return -1; in find_open_flag()
420 int fd = -1; in safe_open_or_create()
432 * that succeeds, we're free to set any file-mode bits on it. (The in safe_open_or_create()
433 * motivation is that we want to set those file-mode bits independently in safe_open_or_create()
439 * file-mode bits on the preexistent file. in safe_open_or_create()
451 if (fd == -1 && errno == EEXIST) { in safe_open_or_create()
455 if (fd == -1) { in safe_open_or_create()
462 if ((oflag & O_CREAT) && fchmod(fd, DEFAULT_NEW_FILE_MODE) == -1) { in safe_open_or_create()
463 error_setg_errno(errp, errno, "failed to set permission " in safe_open_or_create()
477 if (f == NULL && fd != -1) { in safe_open_or_create()
496 slog("guest-file-open called, filepath: %s, mode: %s", path, mode); in qmp_guest_file_open()
500 return -1; in qmp_guest_file_open()
503 /* set fd non-blocking to avoid common use cases (like reading from a in qmp_guest_file_open()
508 error_setg_errno(errp, errno, "Failed to set FD nonblocking"); in qmp_guest_file_open()
509 return -1; in qmp_guest_file_open()
515 return -1; in qmp_guest_file_open()
518 slog("guest-file-open, handle: %" PRId64, handle); in qmp_guest_file_open()
527 slog("guest-file-close called, handle: %" PRId64, handle); in qmp_guest_file_close()
532 ret = fclose(gfh->fh); in qmp_guest_file_close()
547 FILE *fh = gfh->fh; in guest_file_read_unsafe()
551 if (gfh->state == RW_STATE_WRITING) { in guest_file_read_unsafe()
557 gfh->state = RW_STATE_NEW; in guest_file_read_unsafe()
567 read_data->count = read_count; in guest_file_read_unsafe()
568 read_data->eof = feof(fh); in guest_file_read_unsafe()
570 read_data->buf_b64 = g_base64_encode(buf, read_count); in guest_file_read_unsafe()
572 gfh->state = RW_STATE_READING; in guest_file_read_unsafe()
595 fh = gfh->fh; in qmp_guest_file_write()
597 if (gfh->state == RW_STATE_READING) { in qmp_guest_file_write()
599 if (ret == -1) { in qmp_guest_file_write()
603 gfh->state = RW_STATE_NEW; in qmp_guest_file_write()
606 buf = qbase64_decode(buf_b64, -1, &buf_len, errp); in qmp_guest_file_write()
623 slog("guest-file-write failed, handle: %" PRId64, handle); in qmp_guest_file_write()
626 write_data->count = write_count; in qmp_guest_file_write()
627 write_data->eof = feof(fh); in qmp_guest_file_write()
628 gfh->state = RW_STATE_WRITING; in qmp_guest_file_write()
658 fh = gfh->fh; in qmp_guest_file_seek()
660 if (ret == -1) { in qmp_guest_file_seek()
663 /* file is non-seekable, stdio shouldn't be buffering anyways */ in qmp_guest_file_seek()
664 gfh->state = RW_STATE_NEW; in qmp_guest_file_seek()
668 seek_data->position = ftell(fh); in qmp_guest_file_seek()
669 seek_data->eof = feof(fh); in qmp_guest_file_seek()
670 gfh->state = RW_STATE_NEW; in qmp_guest_file_seek()
687 fh = gfh->fh; in qmp_guest_file_flush()
692 gfh->state = RW_STATE_NEW; in qmp_guest_file_flush()
707 g_free(mount->dirname); in free_fs_mount_list()
708 g_free(mount->devtype); in free_fs_mount_list()
771 slog("guest-fsfreeze called"); in qmp_guest_fsfreeze_freeze_list()
776 return -1; in qmp_guest_fsfreeze_freeze_list()
782 return -1; in qmp_guest_fsfreeze_freeze_list()
811 slog("guest-fsthaw called"); in qmp_guest_fsfreeze_thaw()
845 rawpasswddata = (char *)qbase64_decode(password, -1, &rawpasswdlen, errp); in qmp_guest_set_user_password()
865 const char *crypt_flag = crypted ? "-H" : "-h"; in qmp_guest_set_user_password()
866 const char *argv[] = {"pw", "usermod", "-n", username, in qmp_guest_set_user_password()
871 const char *crypt_flag = crypted ? "-e" : NULL; in qmp_guest_set_user_password()
875 ga_run_command(argv, chpasswddata, "set user password", &local_err); in qmp_guest_set_user_password()
888 for (; head; head = head->next) { in guest_find_interface()
889 if (strcmp(head->value->name, name) == 0) { in guest_find_interface()
890 return head->value; in guest_find_interface()
910 return -1; in guest_get_network_stats()
913 while (getline(&line, &n, fp) != -1) { in guest_get_network_stats()
932 if (colon - name_len == trim_line && in guest_get_network_stats()
942 stats->rx_bytes = rx_bytes; in guest_get_network_stats()
943 stats->rx_packets = rx_packets; in guest_get_network_stats()
944 stats->rx_errs = rx_errs; in guest_get_network_stats()
945 stats->rx_dropped = rx_dropped; in guest_get_network_stats()
946 stats->tx_bytes = tx_bytes; in guest_get_network_stats()
947 stats->tx_packets = tx_packets; in guest_get_network_stats()
948 stats->tx_errs = tx_errs; in guest_get_network_stats()
949 stats->tx_dropped = tx_dropped; in guest_get_network_stats()
961 return -1; in guest_get_network_stats()
982 if (sock == -1) { in guest_get_hw_addr()
988 pstrcpy(ifr.ifr_name, IF_NAMESIZE, ifa->ifa_name); in guest_get_hw_addr()
989 if (ioctl(sock, SIOCGIFHWADDR, &ifr) == -1) { in guest_get_hw_addr()
997 ifa->ifa_name, strerror(errno)); in guest_get_hw_addr()
1000 ifa->ifa_name, strerror(errno)); in guest_get_hw_addr()
1028 for (ifa = ifap; ifa; ifa = ifa->ifa_next) { in qmp_guest_network_get_interfaces()
1039 g_debug("Processing %s interface", ifa->ifa_name); in qmp_guest_network_get_interfaces()
1041 info = guest_find_interface(head, ifa->ifa_name); in qmp_guest_network_get_interfaces()
1045 info->name = g_strdup(ifa->ifa_name); in qmp_guest_network_get_interfaces()
1050 if (!info->hardware_address) { in qmp_guest_network_get_interfaces()
1055 info->hardware_address = in qmp_guest_network_get_interfaces()
1063 if (ifa->ifa_addr && in qmp_guest_network_get_interfaces()
1064 ifa->ifa_addr->sa_family == AF_INET) { in qmp_guest_network_get_interfaces()
1066 p = &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr; in qmp_guest_network_get_interfaces()
1073 address_item->ip_address = g_strdup(addr4); in qmp_guest_network_get_interfaces()
1074 address_item->ip_address_type = GUEST_IP_ADDRESS_TYPE_IPV4; in qmp_guest_network_get_interfaces()
1076 if (ifa->ifa_netmask) { in qmp_guest_network_get_interfaces()
1077 /* Count the number of set bits in netmask. in qmp_guest_network_get_interfaces()
1079 p = &((struct sockaddr_in *)ifa->ifa_netmask)->sin_addr; in qmp_guest_network_get_interfaces()
1080 address_item->prefix = ctpop32(((uint32_t *) p)[0]); in qmp_guest_network_get_interfaces()
1082 } else if (ifa->ifa_addr && in qmp_guest_network_get_interfaces()
1083 ifa->ifa_addr->sa_family == AF_INET6) { in qmp_guest_network_get_interfaces()
1085 p = &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr; in qmp_guest_network_get_interfaces()
1092 address_item->ip_address = g_strdup(addr6); in qmp_guest_network_get_interfaces()
1093 address_item->ip_address_type = GUEST_IP_ADDRESS_TYPE_IPV6; in qmp_guest_network_get_interfaces()
1095 if (ifa->ifa_netmask) { in qmp_guest_network_get_interfaces()
1096 /* Count the number of set bits in netmask. in qmp_guest_network_get_interfaces()
1098 p = &((struct sockaddr_in6 *)ifa->ifa_netmask)->sin6_addr; in qmp_guest_network_get_interfaces()
1099 address_item->prefix = in qmp_guest_network_get_interfaces()
1111 address_tail = &info->ip_addresses; in qmp_guest_network_get_interfaces()
1113 address_tail = &(*address_tail)->next; in qmp_guest_network_get_interfaces()
1117 info->has_ip_addresses = true; in qmp_guest_network_get_interfaces()
1119 if (!info->statistics) { in qmp_guest_network_get_interfaces()
1121 if (guest_get_network_stats(info->name, interface_stat) == -1) { in qmp_guest_network_get_interfaces()
1124 info->statistics = interface_stat; in qmp_guest_network_get_interfaces()
1154 double seconds = (double)user_info->ut_tv.tv_sec; in ga_get_login_time()
1155 double useconds = (double)user_info->ut_tv.tv_usec; in ga_get_login_time()
1176 } else if (user_info->ut_type != USER_PROCESS) { in qmp_guest_get_users()
1178 } else if (g_hash_table_contains(cache, user_info->ut_user)) { in qmp_guest_get_users()
1179 value = g_hash_table_lookup(cache, user_info->ut_user); in qmp_guest_get_users()
1183 if (login_time < user->login_time) { in qmp_guest_get_users()
1184 user->login_time = login_time; in qmp_guest_get_users()
1190 user->user = g_strdup(user_info->ut_user); in qmp_guest_get_users()
1191 user->login_time = ga_get_login_time(user_info); in qmp_guest_get_users()
1193 g_hash_table_insert(cache, user->user, user); in qmp_guest_get_users()
1205 * is done in place -- returned value is in the original string.
1240 p--; in ga_osrelease_replace_special()
1253 gchar *content = NULL; in ga_parse_osrelease() local
1257 const char *group = "[os-release]\n"; in ga_parse_osrelease()
1259 if (!g_file_get_contents(fname, &content, NULL, &err)) { in ga_parse_osrelease()
1260 slog("failed to read '%s', error: %s", fname, err->message); in ga_parse_osrelease()
1264 if (!g_utf8_validate(content, -1, NULL)) { in ga_parse_osrelease()
1265 slog("file is not utf-8 encoded: %s", fname); in ga_parse_osrelease()
1268 content2 = g_strdup_printf("%s%s", group, content); in ga_parse_osrelease()
1270 if (!g_key_file_load_from_data(keys, content2, -1, G_KEY_FILE_NONE, in ga_parse_osrelease()
1272 slog("failed to parse file '%s', error: %s", fname, err->message); in ga_parse_osrelease()
1276 g_free(content); in ga_parse_osrelease()
1282 g_free(content); in ga_parse_osrelease()
1300 info->kernel_version = g_strdup(kinfo.version); in qmp_guest_get_osinfo()
1301 info->kernel_release = g_strdup(kinfo.release); in qmp_guest_get_osinfo()
1302 info->machine = g_strdup(kinfo.machine); in qmp_guest_get_osinfo()
1308 osrelease = ga_parse_osrelease("/etc/os-release"); in qmp_guest_get_osinfo()
1310 osrelease = ga_parse_osrelease("/usr/lib/os-release"); in qmp_guest_get_osinfo()
1318 value = g_key_file_get_value(osrelease, "os-release", osfield, NULL); \ in qmp_guest_get_osinfo()
1321 info->field = value; \ in qmp_guest_get_osinfo()
1349 long len = -1; in qga_get_host_name()
1387 ret->load1m = loadavg[0]; in qmp_guest_get_load()
1388 ret->load5m = loadavg[1]; in qmp_guest_get_load()
1389 ret->load15m = loadavg[2]; in qmp_guest_get_load()