From 0a2dc614d9c080d982772f2fae336bd565847592 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Wed, 18 Nov 2020 22:36:30 +1030 Subject: [PATCH] Add license header. --- audio-cmd.c | 18 +++++++++++++ dbindex.c | 18 +++++++++++++ dbindex.h | 18 +++++++++++++ disk-indexer.c | 18 +++++++++++++ disk-monitor.c | 72 ++++++++++++++++++++++++++++++------------------- input-monitor.c | 44 +++++++++++++++++++++--------- music-player.c | 25 ++++++++--------- notify.c | 18 +++++++++++++ notify.h | 18 +++++++++++++ 9 files changed, 197 insertions(+), 52 deletions(-) diff --git a/audio-cmd.c b/audio-cmd.c index 171a001..7896273 100644 --- a/audio-cmd.c +++ b/audio-cmd.c @@ -1,3 +1,21 @@ +/* audio-cmd.c: Sends commands to music player. + + Copyright (C) 2019 Michael Zucchi + + This program is free software: you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + . +*/ #include #include diff --git a/dbindex.c b/dbindex.c index 21313d7..631f255 100644 --- a/dbindex.c +++ b/dbindex.c @@ -1,3 +1,21 @@ +/* dbindex.c: Database frontend for music file database. + + Copyright (C) 2019 Michael Zucchi + + This program is free software: you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + . +*/ #include #include #include diff --git a/dbindex.h b/dbindex.h index 21a5e56..788bb92 100644 --- a/dbindex.h +++ b/dbindex.h @@ -1,3 +1,21 @@ +/* dbindex.h: Database abstraction api. + + Copyright (C) 2019 Michael Zucchi + + This program is free software: you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + . +*/ #include "ez-blob.h" diff --git a/disk-indexer.c b/disk-indexer.c index 84987e2..40f28d4 100644 --- a/disk-indexer.c +++ b/disk-indexer.c @@ -1,3 +1,21 @@ +/* disk-indexer.c: Indexes music files. + + Copyright (C) 2019 Michael Zucchi + + This program is free software: you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + . +*/ #include #include diff --git a/disk-monitor.c b/disk-monitor.c index 1911395..0b90c0b 100644 --- a/disk-monitor.c +++ b/disk-monitor.c @@ -1,3 +1,21 @@ +/* disk-monitor.c: Monitors uevents for removable disks. + + Copyright (C) 2019 Michael Zucchi + + This program is free software: you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + . +*/ /* disk-monitor @@ -8,7 +26,7 @@ - + FIXME: make a setuid-root binary @@ -16,7 +34,7 @@ FIXME: wrap in as-root { - ... + ... mount/unmount } @@ -105,7 +123,7 @@ struct mdisk { ez_node en; char *dev; - + struct dbdisk disk; }; @@ -123,14 +141,14 @@ static int mdisk_equals(const void *ap, const void *bp) { static void mdisk_free(void *mp) { struct mdisk *m = mp; - + free(m->dev); - + free(m->disk.uuid); free(m->disk.label); free(m->disk.type); free(m->disk.mount); - + free(m); } @@ -141,7 +159,7 @@ static void print_values(const char *dev, blkid_probe p) { for (i=0;imount_base_size + uuid_size + 2); @@ -216,7 +234,7 @@ static void partition_add(struct monitor *m, const char *dev) { struct mdisk *md = malloc(sizeof(*md)); memset(md, 0, sizeof(*md)); - + md->dev = strdup(dev); md->disk.uuid = strdup(uuid); md->disk.type = strdup(type); @@ -249,7 +267,7 @@ static void partition_remove(struct monitor *m, const char *dev) { }; struct mdisk *md; int res; - + printf("Remove partition: %s\n", dev); md = ez_set_remove(m->mounts, &mde); @@ -257,7 +275,7 @@ static void partition_remove(struct monitor *m, const char *dev) { partition_notify(m, NOTIFY_DISK_REMOVE, md); res = umount2(md->disk.mount, MNT_DETACH); - + if (res == 0) { printf(" unmount %s @ %s\n", md->dev, md->disk.mount); } else { @@ -272,7 +290,7 @@ static void partition_remove(struct monitor *m, const char *dev) { struct oldnode { ez_node ln; - + dev_t dev; char *mount; }; @@ -280,7 +298,7 @@ struct oldnode { // scan to see if any partitions are already mounted static void partition_check(struct monitor *m) { DIR *dir = opendir(m->mount_base); - + if (dir) { struct stat dstat; struct stat estat; @@ -289,7 +307,7 @@ static void partition_check(struct monitor *m) { ez_list old = EZ_INIT_LIST(old); fstat(dfd, &dstat); - + while (e = readdir(dir)) { if (fstatat(dfd, e->d_name, &estat, AT_SYMLINK_NOFOLLOW) == 0 && S_ISDIR(estat.st_mode) @@ -303,7 +321,7 @@ static void partition_check(struct monitor *m) { ez_list_addtail(&old, onode); } } - + closedir(dir); if (!ez_list_empty(&old)){ @@ -319,7 +337,7 @@ static void partition_check(struct monitor *m) { char devname[strlen("/dev/") + strlen(e->d_name) + 1]; sprintf(devname, "/dev/%s", e->d_name); - + partition_add(m, devname); ez_node_remove(w); free(w->mount); @@ -363,7 +381,7 @@ static void monitor(void) { struct iovec iov; bind(s, (void *)&addr, sizeof(addr)); - + iov.iov_base = data; iov.iov_len = 8192; @@ -380,16 +398,16 @@ static void monitor(void) { m->mounts = ez_set_new(mdisk_hash, mdisk_equals, mdisk_free); res = mkdir(m->mount_base, 0777); m->indexer = notify_writer_new(NOTIFY_INDEXER); - + partition_check(m); printf("Monitoring uevents\n"); - + while ((res = recvmsg(s, &msg, 0)) >= 0) { // ignore snot from udevd if (strcmp(data, "libudev") == 0) continue; - + char *x = data, *e = data+res; char *action; char *dev; @@ -404,11 +422,11 @@ static void monitor(void) { } else if (strncmp(x, "DEVTYPE=", 8) == 0) { type = x+8; } - + x += strlen(x) + 1; } //printf("\n"); - + if (dev && type && strcmp(type, "partition") == 0) { char name[strlen(dev) + strlen("/dev/") + 1]; @@ -428,7 +446,7 @@ static void monitor(void) { notify_close(m->indexer); free(m->mount_base); ez_set_free(m->mounts); - + close(s); } diff --git a/input-monitor.c b/input-monitor.c index 8393e2d..a82c496 100644 --- a/input-monitor.c +++ b/input-monitor.c @@ -1,3 +1,21 @@ +/* input-monitor.c: Monitors keyboard input. + + Copyright (C) 2019 Michael Zucchi + + This program is free software: you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + . +*/ /** This monitors the keyboard. @@ -48,7 +66,7 @@ $ xinput set-int-prop XXX "Device Enabled" 8 0 /dev/input/by-id/usb-2.4G_Wireless_Receiver-event-kbd - + enter: 28 KEY_ENTER home: 102 KEY_HOME @@ -107,7 +125,7 @@ static const struct keymap map[] = { static int cmp_key(const void *ap, const void *bp) { int needle = *((uint16_t *)ap); const struct keymap *hay = bp; - + return needle - hay->code; } @@ -122,13 +140,13 @@ struct monitor *monitor_new(void) { goto fail1; m->player = notify_writer_new(NOTIFY_PLAYER); - + return m; fail1: close(m->keyfd); fail: free(m); - + return NULL; } @@ -149,7 +167,7 @@ static void monitor_event(struct monitor *m, struct input_event *ev) { if (ev->value) { if (key->action == NOTIFY_PLAY_SEEK) { struct notify_play_seek msg; - + switch (key->mode) { case 0: msg.mode = 0; @@ -168,7 +186,7 @@ static void monitor_event(struct monitor *m, struct input_event *ev) { } else { notify_msg_send(m->player, key->action, 0, NULL); } - + if (key->flags & GEN_REPEAT) { printf("start repeat\n"); m->repeat = *ev; @@ -199,9 +217,9 @@ static void monitor_event(struct monitor *m, struct input_event *ev) { case KEY_F2: // cross case KEY_F3: // circle case KEY_F4: // triangle - + case KEY_HOME: // house button - + case KEY_UP: // face panel up case KEY_DOWN: // face panel down case KEY_LEFT: // face panel left @@ -219,16 +237,16 @@ static void monitor_event(struct monitor *m, struct input_event *ev) { case KEY_TV: // 'output' button break; - + } */ void monitor(struct monitor *m) { struct pollfd polla[2]; struct input_event ev; - + // NB: if the player isn't running this will block - + polla[0].fd = m->keyfd; polla[0].events = POLLIN; polla[1].fd = m->mousefd; @@ -242,14 +260,14 @@ void monitor(struct monitor *m) { for (int i=0;i<2;i++) { if (polla[i].revents & POLLERR) return; - + if (polla[i].revents & POLLIN ){ read(polla[i].fd, &ev, sizeof(ev)); monitor_event(m, &ev); } } } else if (res == 0) { - monitor_event(m, &m->repeat); + monitor_event(m, &m->repeat); } } } diff --git a/music-player.c b/music-player.c index 1e4d275..70e02d2 100644 --- a/music-player.c +++ b/music-player.c @@ -1,19 +1,20 @@ -/* - Copyright (C) 2019 Michael Zucchi +/* music-player.c: Music player server. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. + Copyright (C) 2019,2020 Michael Zucchi - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is free software: you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. - You should have received a copy of the GNU General Public License - along with this program. If not, see . + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see + . */ #include diff --git a/notify.c b/notify.c index c9a1d31..8edbf3e 100644 --- a/notify.c +++ b/notify.c @@ -1,3 +1,21 @@ +/* notify.c: Service IPC via POSIX message queues. + + Copyright (C) 2019 Michael Zucchi + + This program is free software: you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + . +*/ #include #include diff --git a/notify.h b/notify.h index b6cc3a2..58e9bf7 100644 --- a/notify.h +++ b/notify.h @@ -1,3 +1,21 @@ +/* notify.c: Service IPC API via POSIX message queues. + + Copyright (C) 2019 Michael Zucchi + + This program is free software: you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + . +*/ #ifndef _NOTIFY_H #define _NOTIFY_H -- 2.39.5