Android Training Course (39)

Source: Internet
Author: User

<! -- @ Page {margin: 2 cm} P {margin-bottom: 0.21} -->

In the init. rc file, you can see the following services loaded:

Service installd/system/bin/installd

Socket installd stream 600 system

The code of the installd service is in the directory:

Android-2.0/frameworks/base/cmds/installd

 

Installd is a service for installing dex files.

Its main entry function code is as follows:

Int main (const int argc, const char * argv []) {

Char buf [BUFFER_MAX];

Struct sockaddr addr;

Socklen_t alen;

Int lsocket, s, count;

 

Create a controlled SOCKET.

Lsocket = android_get_control_socket (SOCKET_PATH );

If (lsocket <0 ){

LOGE ("Failed to get socket from environment: % s", strerror (errno ));

Exit (1 );

}

 

Listen to this SOCKET.

If (listen (lsocket, 5 )){

LOGE ("Listen on socket failed: % s", strerror (errno ));

Exit (1 );

}

Fcntl (lsocket, F_SETFD, FD_CLOEXEC );

 

Process the received SOCKET connection in a loop.

 

For (;;){

Alen = sizeof (addr );

S = accept (lsocket, & addr, & alen );

If (s <0 ){

LOGE ("Accept failed: % s", strerror (errno ));

Continue;

}

Fcntl (s, F_SETFD, FD_CLOEXEC );

 

Receive and process commands from the new connection.

LOGI ("new connection ");

For (;;){

Unsigned short count;

If (readx (s, & count, sizeof (count ))){

LOGE ("failed to read size ");

Break;

}

If (count <1) | (count> = BUFFER_MAX )){

LOGE ("invalid size % d", count );

Break;

}

If (readx (s, buf, count )){

LOGE ("failed to read command ");

Break;

}

Buf [count] = 0;

If (execute (s, buf) break;

}

LOGI ("closing connection ");

Close (s );

}

 

Return 0;

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.