예제 #1
0
static int hook_close(struct tracy_event *e)
{
	int rc = TRACY_HOOK_CONTINUE;
	struct multiboot_child_data *mbc = e->child->custom;

	if (e->child->pre_syscall) {
		int fd = (int)e->args.a0;
		struct tracy_ll_item *item = ll_find(mbc->files, fd);

		if (item) {
			struct fd_info *fdi = item->data;
			ERROR("close(%d|%s)\n", fd, fdi->filename);

			// TODO detect format
			if (fs_was_format(fdi)) {
				DEBUG("FORMAT DETECTED!\n");
				struct fstab_rec *fstabrec =
				    get_fstab_rec(fdi->filename);
				if (fstabrec) {
					INFO("format path %s...\n",
					     fstabrec->replacement_device);
					char buf[PATH_MAX];
					snprintf(buf, sizeof(buf), "%s/*",
						 fstabrec->replacement_device);
					format_path(buf);
				}
			}

			free_fdinfo(fdi);
			ll_del(mbc->files, fd);
		}
	}

	return rc;
}
예제 #2
0
파일: soxy.c 프로젝트: MerlijnWajer/tracy
static int proxy_set(struct tracy_event *e, int fd, proxy_t *proxy) {
    if(proxy == NULL) {
        return ll_del(cproxy(e->child->custom)->ll, fd);
    }
    else {
        return ll_add(cproxy(e->child->custom)->ll, fd, proxy);
    }
}
예제 #3
0
파일: tracy.c 프로젝트: HetGroteBos/tracy
int tracy_remove_child(struct tracy_child *c) {
    int r;
    r = ll_del(c->tracy->childs, c->pid);

    if (!r)
        free(c);

    return r;
}
예제 #4
0
int main(int argc, char** argv){
    if(argc == 1){ 
        printf("Please specify input file\n");
        exit(1);
    }

    FILE* f = fopen(argv[1], "r");
    
    if(!f){
        printf("File not found: %s\n", argv[1]);
        exit(1);
    }

    int pc = 0; /* Position in stream of current instruction */
    
    char mem[1024]; /* Memory array */
    char* dp = mem; /* Data pointer */

    bool debug = false;
    int line = 1;

    for(int i=0; i < 1024; ++i) mem[i] = 0;
    int c;
    do{
        c = getc(f); pc++;
        if (debug) printf("Character: %c, line: %d\n", c, line);
        switch(c){
            case '\n':
                if(debug) printf("Line %d\n", line);
                line += 1; break;
            case '>':
                dp++; break;
            case '<':
                dp--; break;
            case '+':
                (*dp)++; break;
            case '-':
                (*dp)--; break;
            case '.': 
                if(debug) printf("Print statement: %d\n", line);
                printf("%c", *dp); break;
            case ',': 
                (*dp) = getchar(); break;
            case '[': 
                if(*dp == 0){ /* If pointer is zero, find matching closing bracket */
                    int depth = 1;
                    do{
                        c = getc(f); pc++;
                        if(debug){ 
                            printf("depth = %d\n", depth);
                            printf("%c", c);
                        }
                        if(c == 91) depth += 1;
                        else if(c == 93) depth -=1;
                        else if(c == 10) line += 1;
                        else if(c == EOF){
                            printf("Unmatched bracket at %d", top->pos);
                            exit(1);
                        }
                    } while(depth != 0);
                }
                else{ /* else push the position onto the stack and move to next instruction */
                    ll_push(pc, line);
                    if(debug){
                        printf("[ not taken\n");
                        print_stack();
                    }
                }
                break;
            case ']':
                if(*dp){ /* Loop back to beginning, but don't remove loop start point from stack */
                    struct ll* st = ll_peek();
                    pc = st->pos;
                    line = st->line;
                    fseek(f, pc, SEEK_SET);
                }
                else{ /* Finished looping, remove loop start from stack */
                    ll_del();
                    if(debug){
                        printf("Popped stack");
                        print_stack();
                    }
                }
                break;
        }

    } while (c!=EOF);
    printf("\n");
}
예제 #5
0
파일: hashmap.c 프로젝트: cbh34680/jbx
int hm_set(const struct hashmap_st* hm, const char* key, void* val, void** old_val)
{
	int syserr = -1;

	assert(hm);
	assert(key);

	int idx = hm_str2code(key) % (int)hm->array_num;

	struct kv_st* kv = NULL;

	struct lnklst_st* ll = hm->array[idx];
	if (! ll)
	{
		if (! val)
		{
			if (old_val)
			{
				*old_val = NULL;
			}

			syserr = 0;
			goto EXIT_LABEL;
		}

		ll = ll_init(free_kv_);
		if (! ll)
		{
			goto EXIT_LABEL;
		}

		hm->array[idx] = ll;
	}

	struct lnkelm_st* le = ll_search(ll, NULL, cmp_by_key_, key);

	if (le)
	{
		struct kv_st* tmp_kv = le->val;
		if (old_val)
		{
			*old_val = tmp_kv->val;
		}

		if (val)
		{
			tmp_kv->val = val;
		}
		else
		{
			ll_del(ll, le);
		}
	}
	else
	{
		if (old_val)
		{
			*old_val = NULL;
		}

		if (! val)
		{
			syserr = 0;
			goto EXIT_LABEL;
		}

		kv = calloc(1, sizeof(struct kv_st));
		if (! kv)
		{
			goto EXIT_LABEL;
		}

		kv->key = strdup(key);
		if (! kv->key)
		{
			goto EXIT_LABEL;
		}

		kv->val = val;

		void* ok = ll_add_tail(ll, kv);
		if (! ok)
		{
			goto EXIT_LABEL;
		}
	}

	syserr = 0;

EXIT_LABEL:

	if (syserr)
	{
		if (kv)
		{
			free(kv->key);
			free(kv);
		}
	}

	return syserr;
}