Przeglądaj źródła

vccd: now we can get system info by a command

intirain 4 lat temu
rodzic
commit
00d1ef8428
7 zmienionych plików z 54 dodań i 7 usunięć
  1. 1 1
      Makefile
  2. 5 1
      include/vcc/vcc.h
  3. 11 0
      include/vcc/vccd.h
  4. 2 2
      include/vcc/version.h
  5. 23 1
      monitor.c
  6. 1 1
      users.c
  7. 11 1
      vcc.c

+ 1 - 1
Makefile

@@ -1,5 +1,5 @@
 VCCD_MAJOR 		= 1
-VCCD_MINOR 		= 13
+VCCD_MINOR 		= 14
 VCCD_PATCH 		= 0
 VCCD_STR 		= -rc 
 

+ 5 - 1
include/vcc/vcc.h

@@ -66,7 +66,11 @@
 
 /* server -> client. new message */
 #define REQ_REL_NEW 	12
-#define REQ_MAX 	13
+
+/* client -> server. get server info. (root required) */
+#define REQ_SYS_INFO 	13
+
+#define REQ_MAX 	14
 
 #define REQ_SIZE 	512
 #define USRNAME_SIZE 	32

+ 11 - 0
include/vcc/vccd.h

@@ -75,8 +75,19 @@ int join_session(int sid, int fd);
 
 int get_user_info(int fd, struct vcc_request *);
 int incr_score(int fd, struct vcc_request *);
+int monitor_info(int fd, struct vcc_request *);
 
 int relay_new_msg(int fd, void *);
+int send_to(int fd, const char *restrict msg, int is_only_visible, const struct vcc_relay_header *restrict hdr, 
+		int size);
+
+static inline int relay_send_msg(int fd, const char *restrict msg, const char *restrict usrname) {
+	struct vcc_relay_header hdr;
+
+	strcpy(hdr.usrname, usrname);
+	return send_to(fd, msg, 1, &hdr, strlen(msg));
+}
+
 int relay_broadcast(const char *restrict msg, int expect, 
 		const struct vcc_relay_header *restrict hdr);
 int relay_send_to(const char *restrict msg, const char *restrict visible, int expect_fd, 

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCCD_VERSION "vccd 1.13.0 Fri Jun  3 05:10:49 PM CST 2022 root"
-#define VCCD_SEMVER "vccd 1.13.0-rc "
+#define VCCD_VERSION "vccd 1.14.0 Wed Jun  8 12:57:16 PM CST 2022 root"
+#define VCCD_SEMVER "vccd 1.14.0-rc "

+ 23 - 1
monitor.c

@@ -31,7 +31,7 @@
 
 
 int allocated, current;
-extern int nusers;
+extern int nusers, system_fd;
 
 #if CONFIG_ADVANCED_AMALLOC
 
@@ -126,4 +126,26 @@ int amalloc_report(char *s) {
 }
 
 
+int monitor_info(int fd, struct vcc_request *req) {
+	char msg[128];
+
+	if (fd != system_fd) {
+		relay_send_msg(fd, "sysinfo: only root can do that. ", "system");
+		vcc_log("%d:%s tried to get sysinfo. \n", fd, req->usrname);
+
+		return 1;
+	}
+
+	sprintf(msg, "\namalloc info: \n%d (%d KB) allocated, %d (%d KB) using\n", allocated, allocated >> 10, 
+			current, current >> 10);
+
+	relay_send_msg(fd, msg, "system");
+	vcc_log("sysinfo sent to %d. \n", fd);
+
+	return 0;
+}
+
+
+
+
 

+ 1 - 1
users.c

@@ -370,7 +370,7 @@ int incr_score(int fd, struct vcc_request *req) {
 		out->uid = htonl(-1);
 		vcc_send_req(find_connection(fd), out);
 
-		vcc_log("%d tried to modify the score. \n", fd);
+		vcc_log("%d:%s tried to modify the score. \n", fd, req->usrname);
 
 		return 1;
 	}

+ 11 - 1
vcc.c

@@ -272,7 +272,12 @@ int vcc_new_msg(int fd, struct vcc_request *req) {
 
 	msg = req->msg;
 
-	/* it's not so beautiful... but arguments of each function are not common. */
+	/* it's not so beautiful... but arguments of each function are not common. 
+	 *
+	 * so we CAN'T use requests[htonl(req->reqtype)] cetera instead. 
+	 * f**k. 
+	 * */
+
 	switch (htonl(req->reqtype)) {
 	case REQ_MSG_NEW:
 		/* POLLOUT will be set, just because they sent us a message */
@@ -337,6 +342,11 @@ int vcc_new_msg(int fd, struct vcc_request *req) {
 
 		break;
 
+	case REQ_SYS_INFO:
+		monitor_info(fd, req);
+
+		break;
+
 	default:
 		vcc_log("--- bad request type from %d\n", fd);