summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2012-11-25 20:58:28 +0100
committerPali Rohár <pali.rohar@gmail.com>2012-11-25 20:58:28 +0100
commit355fe9dc62034384c42b1f4d207fb68b3b395b96 (patch)
treefdf427ac9ededdd1cc071610b7c5dfab163d403a /src
parent857123e9e4de410955a90c1096dcdd1d3f41e30e (diff)
download0xFFFF-355fe9dc62034384c42b1f4d207fb68b3b395b96.tar.bz2
Remove old queue mode from tree
Diffstat (limited to 'src')
-rw-r--r--src/Makefile2
-rw-r--r--src/qmode.c161
-rw-r--r--src/qmode.h25
-rw-r--r--src/squeue/squeue.c294
-rw-r--r--src/squeue/squeue.h28
-rw-r--r--src/squeue/squeue.vapi45
6 files changed, 1 insertions, 554 deletions
diff --git a/src/Makefile b/src/Makefile
index a0490fd..fdb4fdd 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -4,7 +4,7 @@ CPPFLAGS += -DVERSION=\"$(VERSION)\" -D_GNU_SOURCE -I.
CFLAGS += -W -Wall -O2 -pedantic -std=c99
LIBS += -lm -lusb
-OBJS = main.o nolo.o printf-utils.o image.o fiasco.o device.o usb-device.o cold-flash.o qmode.o console.o squeue/squeue.o operations.o local.o mkii.o disk.o cal.o
+OBJS = main.o nolo.o printf-utils.o image.o fiasco.o device.o usb-device.o cold-flash.o console.o operations.o local.o mkii.o disk.o cal.o
BIN = 0xFFFF
all: $(BIN)
diff --git a/src/qmode.c b/src/qmode.c
deleted file mode 100644
index 4ae1128..0000000
--- a/src/qmode.c
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * 0xFFFF - Open Free Fiasco Firmware Flasher
- * Copyright (C) 2008 pancake <pancake@youterm.com>
- * Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <signal.h>
-
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-
-#include "global.h"
-
-#include "qmode.h"
-#include "nolo.h"
-
-#if HAVE_SQUEUE
-
-#include "squeue/squeue.h"
-extern int qmode;
-extern struct squeue_t *p;
-
-#endif
-
-#if HAVE_SQUEUE
-
-struct squeue_t *q;
-struct squeue_t *p;
-
-static int fork_enabled = 0;
-static int dofork()
-{
- if (fork_enabled)
- return fork();
- return 0;
-}
-
-static void process_message(char *msg)
-{
- char *str;
- char *arg;
- int c=1;
- if (msg == NULL)
- return;
- printf("[x] (%s)\n", msg);
- str = strdup(msg);
- arg = strchr(str, ':');
- if (c!=0) {
- arg[0]='\0';
- arg = arg +1;
-/* if (!strcmp(str, "flash")) {
- const char *type = fpid_file(arg);
- if (type == NULL) {
- squeue_push2(p, "error", "Unknown piece format", 1);
- } else flash_image(arg, type, NULL, NULL, NULL);
- } else*/
- if (!strcmp(str, "reset")) {
-// if (reboot_board() == 0) {
-// squeue_push2(p,"info", "Device reboots", 1);
-// } else squeue_push2(p,"error", "Cannot reboot device", 1);
- } else
- if (!strcmp(str, "info")) {
-// get_rd_flags();
-// squeue_push2(p, "info", strbuf, 1);
-// get_nolo_version();
-// squeue_push2(p, "info", strbuf, 1);
-// get_usb_mode();
-// squeue_push2(p, "info", strbuf, 1);
- } else
- squeue_push2(p, "error", "invalid command", 0);
- } else {
- squeue_push2(p, "error", "invalid command format", 0);
- }
- free(str);
-}
-
-static void cc(int signum)
-{
- squeue_close(p);
- squeue_close(q);
- printf("pipes closed\n");
- squeue_release("/tmp/0xFFFF.1");
- squeue_release("/tmp/0xFFFF.2");
- exit(1);
-}
-
-int queue_mode(void)
-{
- int pid = 0;
- char *msg;
-
- signal(SIGINT, cc);
-
- pid = dofork();
- if (pid) {
- wait(&pid);
- return 0;
- } else {
- p = squeue_open("/tmp/0xFFFF.1", Q_CREAT);
- q = squeue_open("/tmp/0xFFFF.2", Q_CREAT);
- if (p == NULL || q == NULL) {
- fprintf(stderr, "Cannot open queue files\n");
- return 0;
- }
- chmod("/tmp/0xFFFF.1", 0666);
- chmod("/tmp/0xFFFF.2", 0666);
- pid = dofork();
- if (pid) {
- printf( "Entering into shared queue server mode.\n"
- "Type $ kill -9 %d # to stop\n"
- "NOTE: Manually remove the /tmp/.0xFFFF.* files to solve perm problems\n", pid);
- } else {
- do {
-#if HAVE_USB
-/* if (connect_via_usb()) {
- fprintf(stderr, "Cannot connect to device. It is possibly not in boot stage.\n");
- squeue_push2(p, "error", "Cannot connect to the device", 1);
- return 0;
- }*/
-#endif
- printf("Waiting for a client in shared queues..\n");
- setsid();
- while(1) {
- msg = squeue_get(q, 1);
- if (msg) {
- process_message(msg);
- squeue_pop(q);
- }
- }
- printf("Connection restarted\n");
- } while (1);
- }
- }
- return 0;
-}
-#else
-int queue_mode(void)
-{
- /* dummy */
- fprintf(stderr, "No HAVE_SQUEUE support\n");
- return 1;
-}
-#endif
diff --git a/src/qmode.h b/src/qmode.h
deleted file mode 100644
index 793337b..0000000
--- a/src/qmode.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * 0xFFFF - Open Free Fiasco Firmware Flasher
- * Copyright (C) 2008 pancake <pancake@youterm.com>
- * Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
-
-#ifndef QMODE_H
-#define QMODE_H
-
-int queue_mode(void);
-
-#endif
diff --git a/src/squeue/squeue.c b/src/squeue/squeue.c
deleted file mode 100644
index 69bd595..0000000
--- a/src/squeue/squeue.c
+++ /dev/null
@@ -1,294 +0,0 @@
-#include "squeue.h"
-#define _XOPEN_SOURCE 500 /* Or: #define _BSD_SOURCE */
-#include <unistd.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <sys/ipc.h>
-#include <signal.h>
-#include <sys/shm.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-
-#define POOL_SIZE ITEM_MAX*ITEM_SIZE
-#define ITEM_SIZE 512
-#define ITEM_MAX 10
-
-int squeue_release(const char *file)
-{
- int shmid;
- key_t k = ftok(file, 0xa3);
-
- if (k == -1) {
- perror("ftok");
- return -1;
- }
-
- shmid = shmget(k, POOL_SIZE, 0666);
- if (shmid == -1)
- return -1; // not released
- return shmctl(shmid, IPC_RMID,NULL);
-}
-
-extern int errno;
-struct squeue_t *squeue_open(const char *file, int mode)
-{
- struct squeue_t *q;
- char *pool;
- int shmid;
- key_t k;
-
- k = ftok(file, 0x34);
- if (k == -1) {
- perror("ftok");
- squeue_release(file);
- close(creat(file, 0666));
- chmod(file, 0666);
- k = ftok(file, 0xa3);
- if (k == -1) {
- perror("ftok");
- return NULL;
- }
- }
-_retry:
- shmid = shmget(k, POOL_SIZE, 0666|(mode==Q_CREAT)?IPC_CREAT:0);
- if (shmid == -1) {
- perror("shmget1");
- shmid = shmget(k, POOL_SIZE, 0666|((mode==Q_CREAT)?IPC_CREAT:0));
- if (shmid == -1) {
- perror("shmget2");
- if (errno == EEXIST)
- shmid = shmget(k, POOL_SIZE, 0666 |IPC_CREAT);
-
- if (shmid == -1) {
- if (mode == Q_WAIT) {
- usleep(100);
- goto _retry;
- }
- perror("shmget");
- return NULL;
- }
- }
- }
-
- if (mode == Q_WAIT)
- mode = Q_OPEN;
-
- /* fix perms */
- if (mode == Q_CREAT) {
- struct shmid_ds sd;
- shmctl(shmid, IPC_STAT, &sd);
- sd.shm_perm.uid = 1000;
- sd.shm_perm.gid = 1000;
- sd.shm_perm.mode = sd.shm_perm.mode|0666;
- shmctl(shmid, IPC_SET, &sd);
- }
-
- pool = shmat(shmid, NULL, 0);
- if (pool == (void *)-1) {
- perror("shmat");
- return NULL;
- }
-
- if (mode == Q_CREAT)
- memset(pool, '\0', POOL_SIZE);
-
- q = (struct squeue_t *)malloc(sizeof(struct squeue_t));
- memset(q, '\0', sizeof(struct squeue_t));
- q->shmid = shmid;
- q->pool = pool;
- q->mode = mode;
-
- return q;
-}
-
-void squeue_free(struct squeue_t *q)
-{
- free(q);
-}
-
-int squeue_close(struct squeue_t *q)
-{
- char *pool;
-
- if (q==NULL)
- return -1;
-
- pool = q->pool;
- shmctl(q->shmid, IPC_RMID, NULL);
- free(q);
- return shmdt(pool);
-}
-
-int squeue_push(struct squeue_t *q, const char *str, int lock)
-{
- int i;
-
- if (q==NULL)
- return -1;
-// if (q->mode == Q_CREAT) {
-// printf("squeue_push: cannot push from the creator\n");
-// return -1;
-// }
-
- if (str==NULL||strlen(str)>ITEM_SIZE)
- return -1;
- do {
- if (q->squeue_idx >= ITEM_MAX) {
- while (q->pool[0]!='\0') {
- q->squeue_locks++;
- if (!lock) {
- printf("buffer is full\n");
- return -1;
- }
- usleep(100);
- }
- q->squeue_idx = 0;
- }
-
- for(i=q->squeue_idx*ITEM_SIZE;i<POOL_SIZE;i+=ITEM_SIZE) {
- if (q->pool[i]=='\0') {
- strcpy(q->pool+i, str);
- q->squeue_idx++;
- return 1;
- }
- }
- q->squeue_locks++;
- } while (lock);
- q->squeue_lost++;
-
- return 0;
-}
-
-int squeue_push2(struct squeue_t *q, const char *head, const char *str, int lock)
-{
- int ret;
- char *buf = malloc(strlen(head) + strlen(str) + 2);
- strcpy(buf, head);
- strcat(buf, ":");
- strcat(buf, str);
- ret = squeue_push(q, buf, lock);
- free(buf);
- return ret;
-}
-
-int squeue_pop(struct squeue_t *q)
-{
- int i;
- int two = 1;
-
- if (q==NULL)
- return -1;
-// if (q->mode == Q_OPEN) { // cannot pop when not owner of squeue
-// fprintf(stderr, "squeue_pop: cannot pop when you are not owner.\n");
-// return -1;
-// }
- for(two=1;two--;q->head_idx = 0)
- for(i=q->head_idx*ITEM_SIZE;i<POOL_SIZE;i+=ITEM_SIZE) {
- if (q->pool[i]!='\0') {
- q->pool[i]='\0';
- q->head_idx++;
- q->squeue_pops++;
- return 1;
- }
- }
- q->squeue_oops++;
- fprintf(stderr, "WARNING: race condition detected in squeue.\n");
- return 0;
-}
-
-char *squeue_get(struct squeue_t *q, int lock)
-{
- int i=0;
- int two = 1;
-
- if(q==NULL)
- return NULL;
-// if (q->mode == Q_OPEN) { // cannot pop when not owner of squeue
-// fprintf(stderr, "squeue_get: cannot pop when you are not owner.\n");
-// return NULL;
-// }
- do {
- for(two=1;two--;q->head_idx = 0) {
- for(i=q->head_idx*ITEM_SIZE;i<POOL_SIZE;i+=ITEM_SIZE)
- if (q->pool[i]!='\0')
- return q->pool+i;
- }
- if (lock)
- usleep(100);
- } while (lock);
- return NULL;
-}
-
-void squeue_stats(struct squeue_t *q)
-{
- if(q==NULL)
- return;
- printf("Queue locks: %d\n", q->squeue_locks);
- printf("Queue lost: %d\n", q->squeue_lost);
- printf("Queue oops: %d\n", q->squeue_oops);
- printf("Queue pops: %d\n", q->squeue_pops);
-}
-
-#if _MAIN_
-struct squeue_t *q;
-
-int sigc()
-{
- squeue_stats(q);
- exit(1);
-}
-
-int main()
-{
- char buf[102];
- int i;
- int pid;
-
- signal(SIGINT, sigc);
-
- squeue_release("/dev/null");
-
- pid = fork();
- if (pid) {
- q = squeue_open("/dev/null", Q_CREAT);
- if (q == NULL) {
- perror("oops");
- kill(pid, SIGINT);
- return;
- }
- squeue_push(q, "Hello World", 0);
- squeue_push(q, "jeje msg 2", 0);
-
- while(1) {
- char *uh = squeue_get(q,1);
- if (uh) {
- printf("get: (%s)\n", uh);
- squeue_pop(q);
- }
- usleep(100);
- }
- squeue_close(q);
- } else {
- q = squeue_open("/dev/null", Q_WAIT);
- if (q == NULL) {
- perror("oops");
- return;
- }
- for(i=0;i<128;i++) {
- sprintf(buf, "puta%d", i);
- squeue_push(q, buf, 1);
- usleep(100);
- }
- squeue_stats(q);
- printf("cya\n");
- squeue_close(q);
- }
-
- return 0;
-}
-#endif
diff --git a/src/squeue/squeue.h b/src/squeue/squeue.h
deleted file mode 100644
index e027d51..0000000
--- a/src/squeue/squeue.h
+++ /dev/null
@@ -1,28 +0,0 @@
-struct squeue_t {
- int shmid;
- int mode;
- char *pool;
- /* pointers */
- int head_idx;
- int squeue_idx;
- /* counters */
- int squeue_locks;
- int squeue_lost;
- int squeue_oops;
- int squeue_pops;
-};
-
-
-#define Q_OPEN 0
-#define Q_CREAT 1
-#define Q_WAIT 2
-
-int squeue_release(const char *file);
-struct squeue_t *squeue_open(const char *file, int init);
-int squeue_close(struct squeue_t *q);
-void squeue_free(struct squeue_t *q);
-int squeue_push(struct squeue_t *q, const char *str, int lock);
-int squeue_push2(struct squeue_t *q, const char *head, const char *str, int lock);
-int squeue_pop(struct squeue_t *q);
-char *squeue_get(struct squeue_t *q, int lock);
-void squeue_stats(struct squeue_t *q);
diff --git a/src/squeue/squeue.vapi b/src/squeue/squeue.vapi
deleted file mode 100644
index 09b10e5..0000000
--- a/src/squeue/squeue.vapi
+++ /dev/null
@@ -1,45 +0,0 @@
-using GLib;
-
-[CCode (lower_case_cprefix = "squeue_", cheader_filename = "squeue.h")]
-namespace SQueues {
- [CCode (cname = "struct squeue_t", free_function = "squeue_free")]
- public struct SQueue {
- int shmid;
- int mode;
- char *pool;
- /* pointers */
- int head_idx;
- int queue_idx;
- /* counters */
- int locks;
- int lost;
- int oops;
- int pops;
- [CCode (cname = "squeue_open")]
- public static SQueue* open(string file, int mode);
- [CCode (cname = "squeue_push")]
- public int push(string msg, int l);
- [CCode (cname = "squeue_push2")]
- public int push2(string cmd, string msg, int l);
- [CCode (cname = "squeue_get")]
- public unowned string get(int l);
- [CCode (cname = "squeue_pop")]
- public int pop();
- [CCode (cname = "squeue_stats")]
- public int stats();
- [CCode (cname = "squeue_close")]
- public int close();
- [CCode (cname = "squeue_free")]
- public int free();
- [CCode (cname = "squeue_release")]
- public static int release(string file);
-
- }
-
- [CCode (cprefix = "Q_", cheader_fileneme = "squeue.h")]
- public enum SQueueMode {
- OPEN = 0,
- CREAT = 1,
- WAIT = 2
- }
-}