Changeset ea28272 in mainline for uspace/app/kill/kill.c


Ignore:
Timestamp:
2010-12-30T13:43:27Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d770deb
Parents:
d70d80ed (diff), f418e51 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/app/kill/kill.c

    rd70d80ed rea28272  
    11/*
    2  * Copyright (c) 2006 Ondrej Palkovsky
     2 * Copyright (c) 2010 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
     29/** @addtogroup kill
     30 * @{
     31 */
     32/**
     33 * @file Forecfully terminate a task.
     34 */
     35
     36#include <errno.h>
    2937#include <stdio.h>
    30 #include <unistd.h>
    31 #include <atomic.h>
    32 #include "../tester.h"
     38#include <task.h>
    3339
    34 static atomic_t finish;
     40#define NAME "kill"
    3541
    36 static void callback(void *priv, int retval, ipc_call_t *data)
     42static void print_syntax(void)
    3743{
    38         atomic_set(&finish, 1);
     44        printf("Syntax: " NAME " <task ID>\n");
    3945}
    4046
    41 const char *test_connect(void)
     47int main(int argc, char *argv[])
    4248{
    43         TPRINTF("Connecting to %u...", IPC_TEST_SERVICE);
    44         int phone = ipc_connect_me_to(PHONE_NS, IPC_TEST_SERVICE, 0, 0);
    45         if (phone > 0) {
    46                 TPRINTF("phoneid %d\n", phone);
    47         } else {
    48                 TPRINTF("\n");
    49                 return "ipc_connect_me_to() failed";
     49        char *eptr;
     50        task_id_t taskid;
     51        int rc;
     52
     53        if (argc != 2) {
     54                print_syntax();
     55                return 1;
    5056        }
    51        
    52         printf("Sending synchronous message...\n");
    53         int retval = ipc_call_sync_0_0(phone, IPC_TEST_METHOD);
    54         TPRINTF("Received response to synchronous message\n");
    55        
    56         TPRINTF("Sending asynchronous message...\n");
    57         atomic_set(&finish, 0);
    58         ipc_call_async_0(phone, IPC_TEST_METHOD, NULL, callback, 1);
    59         while (atomic_get(&finish) != 1)
    60                 TPRINTF(".");
    61         TPRINTF("Received response to asynchronous message\n");
    62        
    63         TPRINTF("Hanging up...");
    64         retval = ipc_hangup(phone);
    65         if (retval == 0) {
    66                 TPRINTF("OK\n");
    67         } else {
    68                 TPRINTF("\n");
    69                 return "ipc_hangup() failed";
     57
     58        taskid = strtoul(argv[1], &eptr, 0);
     59        if (*eptr != '\0') {
     60                printf("Invalid task ID argument '%s'.\n", argv[1]);
     61                return 1;
    7062        }
    71        
    72         return NULL;
     63
     64        rc = task_kill(taskid);
     65        if (rc != EOK) {
     66                printf("Failed to kill task with ID %llu (error %d)\n",
     67                    (unsigned long long) taskid, rc);
     68                return 2;
     69        }
     70
     71        return 0;
    7372}
     73
     74/** @}
     75 */
Note: See TracChangeset for help on using the changeset viewer.