1999-02-14 19:03:15 +01:00
|
|
|
/*
|
|
|
|
* Server-side snapshots
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* FIXME: only process snapshots implemented for now
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "winnt.h"
|
|
|
|
#include "tlhelp32.h"
|
1999-05-15 12:48:19 +02:00
|
|
|
|
|
|
|
#include "handle.h"
|
|
|
|
#include "process.h"
|
|
|
|
#include "thread.h"
|
1999-06-22 19:26:53 +02:00
|
|
|
#include "request.h"
|
1999-02-14 19:03:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
struct snapshot
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
|
|
|
struct process_snapshot *process; /* processes snapshot */
|
|
|
|
int process_count; /* count of processes */
|
|
|
|
int process_pos; /* current position in proc snapshot */
|
|
|
|
};
|
|
|
|
|
|
|
|
static void snapshot_dump( struct object *obj, int verbose );
|
|
|
|
static void snapshot_destroy( struct object *obj );
|
|
|
|
|
|
|
|
static const struct object_ops snapshot_ops =
|
|
|
|
{
|
2000-01-01 01:56:27 +01:00
|
|
|
sizeof(struct snapshot), /* size */
|
|
|
|
snapshot_dump, /* dump */
|
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
NULL, /* satisfied */
|
|
|
|
NULL, /* get_poll_events */
|
|
|
|
NULL, /* poll_event */
|
|
|
|
no_read_fd, /* get_read_fd */
|
|
|
|
no_write_fd, /* get_write_fd */
|
|
|
|
no_flush, /* flush */
|
|
|
|
no_get_file_info, /* get_file_info */
|
|
|
|
snapshot_destroy /* destroy */
|
1999-02-14 19:03:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* create a new snapshot */
|
1999-06-22 19:26:53 +02:00
|
|
|
static struct snapshot *create_snapshot( int flags )
|
1999-02-14 19:03:15 +01:00
|
|
|
{
|
|
|
|
struct snapshot *snapshot;
|
1999-06-22 19:26:53 +02:00
|
|
|
|
2000-01-01 01:56:27 +01:00
|
|
|
if ((snapshot = alloc_object( &snapshot_ops, -1 )))
|
1999-06-22 19:26:53 +02:00
|
|
|
{
|
|
|
|
if (flags & TH32CS_SNAPPROCESS)
|
|
|
|
snapshot->process = process_snap( &snapshot->process_count );
|
|
|
|
else
|
|
|
|
snapshot->process_count = 0;
|
|
|
|
snapshot->process_pos = 0;
|
|
|
|
}
|
|
|
|
return snapshot;
|
1999-02-14 19:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get the next process in the snapshot */
|
1999-06-26 10:43:26 +02:00
|
|
|
static int snapshot_next_process( struct snapshot *snapshot, struct next_process_request *req )
|
1999-02-14 19:03:15 +01:00
|
|
|
{
|
|
|
|
struct process_snapshot *ptr;
|
1999-06-26 10:43:26 +02:00
|
|
|
|
1999-02-14 19:03:15 +01:00
|
|
|
if (!snapshot->process_count)
|
|
|
|
{
|
1999-06-22 19:26:53 +02:00
|
|
|
set_error( ERROR_INVALID_PARAMETER ); /* FIXME */
|
1999-02-14 19:03:15 +01:00
|
|
|
return 0;
|
|
|
|
}
|
1999-06-26 10:43:26 +02:00
|
|
|
if (req->reset) snapshot->process_pos = 0;
|
1999-02-14 19:03:15 +01:00
|
|
|
else if (snapshot->process_pos >= snapshot->process_count)
|
|
|
|
{
|
1999-06-22 19:26:53 +02:00
|
|
|
set_error( ERROR_NO_MORE_FILES );
|
1999-02-14 19:03:15 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ptr = &snapshot->process[snapshot->process_pos++];
|
1999-06-26 10:43:26 +02:00
|
|
|
req->pid = ptr->process;
|
|
|
|
req->threads = ptr->threads;
|
|
|
|
req->priority = ptr->priority;
|
1999-02-14 19:03:15 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void snapshot_dump( struct object *obj, int verbose )
|
|
|
|
{
|
|
|
|
struct snapshot *snapshot = (struct snapshot *)obj;
|
|
|
|
assert( obj->ops == &snapshot_ops );
|
|
|
|
fprintf( stderr, "Snapshot: %d processes\n",
|
|
|
|
snapshot->process_count );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void snapshot_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct snapshot *snapshot = (struct snapshot *)obj;
|
|
|
|
assert( obj->ops == &snapshot_ops );
|
|
|
|
if (snapshot->process_count)
|
|
|
|
{
|
|
|
|
for (i = 0; i < snapshot->process_count; i++)
|
|
|
|
release_object( snapshot->process[i].process );
|
|
|
|
free( snapshot->process );
|
|
|
|
}
|
|
|
|
}
|
1999-05-15 12:48:19 +02:00
|
|
|
|
|
|
|
/* create a snapshot */
|
|
|
|
DECL_HANDLER(create_snapshot)
|
|
|
|
{
|
1999-06-22 19:26:53 +02:00
|
|
|
struct snapshot *snapshot;
|
1999-05-15 12:48:19 +02:00
|
|
|
|
1999-06-26 10:43:26 +02:00
|
|
|
req->handle = -1;
|
1999-06-22 19:26:53 +02:00
|
|
|
if ((snapshot = create_snapshot( req->flags )))
|
1999-05-15 12:48:19 +02:00
|
|
|
{
|
1999-06-26 10:43:26 +02:00
|
|
|
req->handle = alloc_handle( current->process, snapshot, 0, req->inherit );
|
1999-06-22 19:26:53 +02:00
|
|
|
release_object( snapshot );
|
1999-05-15 12:48:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the next process from a snapshot */
|
|
|
|
DECL_HANDLER(next_process)
|
|
|
|
{
|
1999-06-26 10:43:26 +02:00
|
|
|
struct snapshot *snapshot;
|
|
|
|
|
|
|
|
if ((snapshot = (struct snapshot *)get_handle_obj( current->process, req->handle,
|
|
|
|
0, &snapshot_ops )))
|
|
|
|
{
|
|
|
|
snapshot_next_process( snapshot, req );
|
|
|
|
release_object( snapshot );
|
|
|
|
}
|
1999-05-15 12:48:19 +02:00
|
|
|
}
|