2017-05-05 17:28:01 +02:00
|
|
|
#ifndef SUBPROCESS_H
|
|
|
|
#define SUBPROCESS_H
|
|
|
|
|
|
|
|
#include "git-compat-util.h"
|
|
|
|
#include "hashmap.h"
|
|
|
|
#include "run-command.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generic implementation of background process infrastructure.
|
2017-06-14 17:12:25 +02:00
|
|
|
* See: Documentation/technical/api-sub-process.txt
|
2017-05-05 17:28:01 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* data structures */
|
|
|
|
|
|
|
|
struct subprocess_entry {
|
|
|
|
struct hashmap_entry ent; /* must be the first member! */
|
|
|
|
const char *cmd;
|
|
|
|
struct child_process process;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* subprocess functions */
|
|
|
|
|
2017-06-30 21:14:05 +02:00
|
|
|
extern int cmd2process_cmp(const void *unused_cmp_data,
|
|
|
|
const struct subprocess_entry *e1,
|
|
|
|
const struct subprocess_entry *e2,
|
|
|
|
const void *unused_keydata);
|
2017-05-05 17:28:01 +02:00
|
|
|
|
|
|
|
typedef int(*subprocess_start_fn)(struct subprocess_entry *entry);
|
|
|
|
int subprocess_start(struct hashmap *hashmap, struct subprocess_entry *entry, const char *cmd,
|
|
|
|
subprocess_start_fn startfn);
|
|
|
|
|
|
|
|
void subprocess_stop(struct hashmap *hashmap, struct subprocess_entry *entry);
|
|
|
|
|
|
|
|
struct subprocess_entry *subprocess_find_entry(struct hashmap *hashmap, const char *cmd);
|
|
|
|
|
|
|
|
/* subprocess helper functions */
|
|
|
|
|
|
|
|
static inline struct child_process *subprocess_get_child_process(
|
|
|
|
struct subprocess_entry *entry)
|
|
|
|
{
|
|
|
|
return &entry->process;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper function that will read packets looking for "status=<foo>"
|
|
|
|
* key/value pairs and return the value from the last "status" packet
|
|
|
|
*/
|
|
|
|
|
2017-05-05 17:28:02 +02:00
|
|
|
int subprocess_read_status(int fd, struct strbuf *status);
|
2017-05-05 17:28:01 +02:00
|
|
|
|
|
|
|
#endif
|